I am not able to connect my program with an exchange server via smtp. So, I tested with the outlook interop and seems working, at least for sending emails and adding attachments. My problem now is adding the header "disposition-notification-to" to the mail message.
Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailMessage = application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Microsoft.Office.Interop.Outlook.MailItem;
mailMessage.Subject = subject;
mailMessage.Recipients.Add(emailAddress);
mailMessage.HTMLBody = bodyString;
mailMessage.PropertyAccessor.SetProperty("urn:schemas:mailheader:disposition-notification-to", notificationAddress);
When it come to set the property I get Exception thrown: System.Runtime.InteropServices.COMException in program.exe
I haven't found an example, and most of the time with other libraries like mailkit usually the mail item have an Headers field.
Thanks in advice for any help
To add a custom MIME header on an outgoing message, you need to set a named property in the
PS_INTERNET_HEADERSnamespace ({00020386-0000-0000-C000-000000000046}). The code below sets"X-MyHeader"MIME header: