In outlook 2007. This is only for the RTF format.
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();
}
}
}
}
However, if I attach multiple attachments. Typically for the second attachment - I get a message "The operation Failed".
This is happening for 2007. Not for 2010 and 2013. instead of attachment.Delete() mail.Attachments.Remove(i);
However the following code works on 2007On 2010 and 2013, it doesn't do a proper removal for the attachment (you can see the icon in the email body) ?
Do you get an exception only in the ItemSend event handler? I'd suggest using another place for such code.