Add attachment to mailItem

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

Add attachment to mailItem
 
Christian Havel




Posts: 181
Joined: 2010-12-30
Hi,

I try to add a attachment to a OL2010 MailItem like following:

mailItem.Save();
attachments = a_mailItem.Attachments;
attachments.Add(fileName, OlAttachmentType.olByValue, null, "My DisplayName");

After the attachments.Add(..) call I check the attachments count and it is still 0.
The file exists.
Any idea what I do wrong?
Thanks,
Christian.
Posted 09 Dec, 2011 02:23:42 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Christian,

First of all, please note that you don't release underlying COM objects properly. You can read more about this in the When to release COM objects in Office add-ins developed in .NET article on our technical blog.

Please try to save the mail item after adding the attachment. Does it help?
.NET, Extended MAPI, Windows Phone & RT
Posted 09 Dec, 2011 02:54:13 Top
Christian Havel




Posts: 181
Joined: 2010-12-30
Hi Eugene,

thanks for your help!

>Please try to save the mail item after adding the attachment. Does it help?
No, it does not help.

At the moment I am trying the following:

object missing = Type.Missing;
mailItem.Save();
attachments = a_mailItem.Attachments;
var addedAttachment = attachments.Add(fileName, missing, missing, "My DisplayName");
mailItem.Save();

Calling addedAttachment.DisplayName returns "My DisplayName", but the attachments.Count is still 0.

Bye,
Christian.
Posted 09 Dec, 2011 02:58:59 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Christian,

Please take a look at the How To: Add an attachment to an Outlook e-mail message and How To: Add an existing Outlook e-mail message as an attachment articles. You can find a complete list of my articles on our technical blog.
.NET, Extended MAPI, Windows Phone & RT
Posted 09 Dec, 2011 03:08:50 Top
Christian Havel




Posts: 181
Joined: 2010-12-30
Hi Eugene,

I am sorry, it was my mistake. I do some actions in the AddAttachment Eventhandler :-)

Bye,
Christian.
Posted 09 Dec, 2011 07:57:58 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
You are welcome, Christian! ;-)
.NET, Extended MAPI, Windows Phone & RT
Posted 09 Dec, 2011 08:11:52 Top