简体   繁体   中英

Is there an easy way to convert from Microsoft.Office.Interop.Outlook.MailItem to System.Net.Mail.MailMessage?

The title pretty much says it all. I have an Outlook interop MailItem . I'd like to create a System.Net.Mail MailMessage from the MailItem , modify a few properties (such as the sender), and then send it. Is this something that must be done manually, or do either of these libraries (or a third party library) provide a simple way to achieve this?

MailItem from Outlook and MailMessage from the .NET Framework are very different things.

You need to do a lot of work manually:

  1. Copy simple properties like subject, sender, to/cc/bcc lists.
  2. Fetch all body formats and create new bodies in MailMessage .
  3. Fetch and store attachments from MailItem using temporary files or memory streams.
  4. Create new attachments for MailMessage using stored data from the previous point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM