Reputation: 1120
I've made program which one of the purposes is to open OutLook client where user can write his email, add attachments etc. After sending I want to get all attachments which were added to email, as well as all email in my program. I tried to handle close event
((Microsoft.Office.Interop.Outlook.ItemEvents_10_Event)email.oMsg).Close += new Microsoft.Office.Interop.Outlook.ItemEvents_10_CloseEventHandler(GetAttachmentsInfo);
and then
if (email.oMsg.Attachments.Count > 0)
{
foreach (Microsoft.Office.Interop.Outlook.Attachment at in email.oMsg.Attachments )
{ attachments.Add(at); }
}
email is OutlookEMail
oMsg is Email Item
attachments is List<Attachment>
but when I close client Attachment throws exception that cannot find object. as well as these in List.
I know that Microsoft.Office.Interop.Outlook.Attachment is not a file, but only something like path to this file containing it name and size. So question : is it possible to save attachments after client is closed in my program? (Without using Email.SaveAttachments os SaveEmail methods, because it uses time and computer space)?
Upvotes: 1
Views: 1924
Reputation: 31641
Here are two other options you could try:
MailItem
additions to the SentItems
Folder via Folder.ItemAdd
.Outlook.Folder sentItems = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder;
sentItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(GetAttachmentsInfo);
MailItem.Send
event.((Outlook.ItemEvents_10_Event)MailItem).Send += new Outlook.ItemEvents_10_SendEventHandler(GetAttachmentsInfo);
Upvotes: 0