【发布时间】:2015-01-20 00:53:16
【问题描述】:
在 Outlook 2007 中。这仅适用于 RTF 格式。
void Application_ItemSend(object Item, ref bool Cancel)
{
Outlook.MailItem mail = Item as Outlook.MailItem;
mail.Save();
Outlook.Attachments attachments = mail.Attachments as Outlook.Attachments;
if (attachments != null)
{
int iTotalAttachments = attachments.Count;
for (int i = iTotalAttachments; i > 0; i--)
{
Outlook.Attachment attachment = attachments[i] as Outlook.Attachment;
// Need to make sure the attachment is not inline
if (attachment != null && attachment.Type != Outlook.OlAttachmentType.olOLE)
{
attachment.Delete();
}
}
}
}
但是,如果我附加多个附件。通常用于第二个附件 - 我收到一条消息“操作失败”。
这发生在 2007 年。不是 2010 年和 2013 年。而不是 attachment.Delete() mail.Attachments.Remove(i);
但是下面的代码在 2007 年 2010 年和 2013 年有效,它没有正确删除附件(您可以在电子邮件正文中看到图标)?
【问题讨论】:
-
看看这个帖子,你必须将它转换为 C# outlookcode.com/threads.aspx?forumid=2&messageid=26228 看看页面底部第二个
Sue Mosher 31-Mar-2008 13:28响应 -
在操作前保存邮件 - 我没有解决问题。
-
您是否已通过代码验证附件是否包含有效信息,您能否报告它在第一次和第二次迭代中显示的内容..?
-
是的。我已经逐步完成了代码。我得到一个带有 {"The operation failed."} 的 COMException。它始终发生在 2007 年和第二次迭代中。附件是简单的文本文件。
-
好的,你已经展示了一些代码......你最初在哪里创建/实例化`COMInterop对象......?你能显示所有相关代码吗
标签: c# outlook-addin outlook-2010 outlook-2007