Accessing/Saving Mailitem as Mailattachment

Add-in Express™ Support Service
That's what is more important than anything else

Accessing/Saving Mailitem as Mailattachment
 
Wolfgang Denz




Posts: 10
Joined: 2011-08-05
Hi,

I have a problem when parsing the attachments of an email-message with my plugin.
When the attachment of a mail is a mail itself (*.msg) I want to save the attched email in RTF-format.

the things I already tried are the following:


//         attached file is of format '.msg'
           saveasType := olRTF;
           attachmentFilename:= ChangeFileExt(attachmentFilename,'.RTF');
// first ettempt
           iAttachment.QueryInterface(IID__MailItem, attachedMail);
           attachedMail.SaveAs(attachmentFilename,saveAsType);
// second attempt
//            attachedMail := GetMailItem(iAttachment as _Mailitem);
//           (IAttachment as _Mailitem).SaveAs(attachmentFileName,saveAsType);
           attachedMail := nil;


Both methods give an exception.
Can you give me a hint how to do that?

Thanks from germany
Wolfgang
Posted 26 Feb, 2013 02:51:32 Top
Andrei Smolin


Add-in Express team


Posts: 14966
Joined: 2006-05-11
Hello Wolfgang,

Here's what Ken Slovak - an Outlook development guru - wrote about this at http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/0f029f31-9005-4763-ae31-9b52f51ef7dd/:


If an attachment is an Outlook item then you can use the SaveAsFile() method with the attachment and save it as a MSG file. Use a file path in a temporary folder and give the attachment a name or use the DisplayName property, then use a "MSG" extension.

Once the file is saved out you can then open it as an Outlook item using Application.CreateItemFromTemplate() using the file path you just created. Then save the item (it will be created and saved in the default folder for that type of item). Then you can leave it there or copy it or move it elsewhere if desired.


Please find more details and useful code fragments (C#) in that thread. Feel free to ask me if you have other questions.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Feb, 2013 05:52:46 Top
Wolfgang Denz




Posts: 10
Joined: 2011-08-05
Works perfect, thanks Andrei

Best regards
Wolfgang

PS: The support of AddinExpress ist really premium
Posted 26 Feb, 2013 06:13:13 Top