在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();
}
}
}
}
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(ⅰ);
但是,以下代码适用于2010年和2013年,它没有正确删除附件(您可以在电子邮件正文中看到图标)?
答案 0 :(得分:0)
您是否仅在ItemSend事件处理程序中获得异常?我建议在其他地方使用此类代码。