【问题标题】:Outlook not showing attachmentsOutlook 不显示附件
【发布时间】:2015-05-06 09:49:52
【问题描述】:

我正在使用 Outlook.Application 和 Outlook.MailItem 对象在我的 C# 桌面应用程序中打开 Outlook。我的 Outlook 不显示附件,尽管当我向自己发送邮件时,我收到带有附件的邮件。但它在发送邮件之前没有显示(当 Outlook 打开时)。我正在使用 Outlook 2007。下面是我的代码:

Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);


 // Create a new mail item.
        Outlook.MailItem oMsg =         (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
......
 //Check if we need to add attachments
if (_files.Count > 0)
{
   foreach (string attachment in _files)
   {
             oMsg.Attachments.Add(attachment,Outlook.OlAttachmentType.olByValue,null,null);
   }
}   

 oMsg.Save();
 oMsg.Display(false);

【问题讨论】:

  • 格式更清晰会更好。我会自己做,但编辑按钮是灰色的。
  • 代码现在已格式化。谢谢。
  • 我能够通过将附件行替换为以下内容来解决上述问题:oMsg.Attachments.Add(attachment, Outlook.OlAttachmentType.olByValue,Type.Missing,Type.Missing);

标签: c# outlook


【解决方案1】:

当然,Type.Missing 用于省略参数,使用 COM 插件中的默认值。

我还建议打破调用链并在单独的代码行上声明每个属性或方法调用。它将允许立即释放每个底层 COM 对象。

使用System.Runtime.InteropServices.Marshal.ReleaseComObject 在您使用完 Outlook 对象后释放它。如果您的加载项尝试枚举存储在 Microsoft Exchange Server 上的集合中的 256 个以上的 Outlook 项目,这一点尤其重要。如果您不及时释放这些对象,您可能会达到 Exchange 对任何一次打开的最大项目数量的限制。然后在 Visual Basic 中将变量设置为 Nothing(在 C# 中为 null)以释放对对象的引用。您可以在 MSDN 的 Systematically Releasing Objects 文章中阅读更多相关信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-18
    • 2013-04-24
    • 2015-10-05
    • 1970-01-01
    • 2015-08-31
    • 2018-06-30
    • 2012-01-17
    • 1970-01-01
    相关资源
    最近更新 更多