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


Guest


Hi Christian,

First of all, please note that you don't release underlying COM objects properly. You can read more about this in the http://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/ article on our technical blog.

Please try to save the mail item after adding the attachment. Does it help?
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


Guest


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


Guest


You are welcome, Christian! ;-)
Posted 09 Dec, 2011 08:11:52 Top