Outlook attachments.Add () does not appear in the message body

I create a new mail item in C # VS-2008 outlook 2007 and attach the file. The first problem is that I do not see the attachment area in the subject line showing the attachment. If I send an email, its properties indicate that there is an attachment, and the size of the email has increased by the amount of the attachment. I just do not see it or not extracting the application.

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 expect the "DisplayName" part to display as the name of the attachment, and I should use the file name.

I do not call .Send () on the email programmatically, I call mailItem.Display (true) to show the email to the user for any final changes. At this point, I can look at the properties and see that there is an application.

If I press send (send to myself), I see the same thing, the application seems to be there, but not accessible.

+3
source share
4 answers

I found a problem. I am changing 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 to olByValue. Using Type.Missing, and now I see the attachment correctly in the email.

+4
source

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

Attachment.Position Property

+3
source

, , , , , . , , mailitems, . , , mailItem null dpleay attechament

0

, , ,

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

also did not help me, so I decided to share an alternative approach. The solution to this problem ended up mailItem.Save();calling you right before the call mailItem.Display(true);. What this will do is update the viewing form to show your attachments. It is also worth noting that it will save the message in drafts. Not a problem if you expect the user to send an email, but if they cancel it, he will remain in the Drafts folder.

0
source

Source: https://habr.com/ru/post/1697641/


All Articles