DEV Community

loading...

Create EML file from System.Net.Mail.MailMessage

Robin van der Knaap
Full stack developer: Jack of al trades, master of none.
Originally published at Medium on ・1 min read

For a project I was working on, I needed to create an EML file from the standard MailMessage class which exists in the System.Net.Mail namespace. I came across an article which describes how to extend the save functionality on the MailMessage class. Using the same technique I created an extension method which is able to save the MailMessage class as EML.

With this extension method in your solution you can create an EML file like this:

The extension method is implemented like this:

Conclusion

EML files are perfect for storing the email message on your file system or in the database. The EML file contains all the data from the email, including attachments. You can open the EML in most mail clients and view the email.

Discussion (1)

Collapse
norm profile image
Norm • Edited

Thank you for this useful post.

Forem Open with the Forem app