DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 968,547 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Robin van der Knaap
Robin van der Knaap

Posted on • Originally published at Medium on

Create EML file from System.Net.Mail.MailMessage

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.

Top comments (1)

Collapse
 
norm profile image
Norm • Edited on

Thank you for this useful post.

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.