views:

3787

answers:

2

I'm creating a new mail item, in C# VS-2008 outlook 2007, and attaching a file. The first issue is that I don't see an attachment area under the subject line showing the attachment. If I send the e-mail its properties show that there is an attachment and the e-mail size has grown by the attachment amount. I just cannot see it or extract the attachment.

Here is the code I'm using:

Outlook.MailItem mailItem = (Outlook.MailItem)this.Application.CreateItem(Outlook.OlItemType.olMailItem);
attachments.Add(ReleaseForm.ZipFile, Outlook.OlAttachmentType.olByValue, 0, "DisplayName");

I am expecting the part "DisplayName" would show as the attachment name and I should be using the filename.

I don't call .Send() on the e-mail programmatically, I call mailItem.Display(true) to show the e-mail to the user for any final edits. At this point I can look at the properties and see that there is an attachment there.

If I press send (sending to myself) I see the same thing, the attachment appears to be there but not accessible.

+4  A: 

I have found the issue. I change the code to use the following:

attachments.Add(ReleaseForm.ZipFile, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);

It appears that the Position and DisplayName parameters control what happens with an olByValue. Using Type.Missing and now I see the attachments correctly in the e-mail.

John Dyer
+1  A: 

By the way, if you will set Position to 0 your attachement will be hidden:

Attachment.Position Property

stic