1

I have a service that is used to automate an e-mail system, it also saves a copy of the .eml file in a local folder.

Using the Outlook Interop dll works fine for interactive applications, however we need to make it a service, which is non-interactive, and making the service interactive would render a lot of security issues.

tl;dr Is there any way to save the .eml file in a folder using a non-interactive Windows Service?

PS: The e-mail is a System.Net.Mail.MailMessage object.

Community
  • 1
  • 1
Lucas
  • 534
  • 1
  • 10
  • 29

1 Answers1

1

System.Net.Mail.SmtpClient contains built in functionality to write the message to disk in .eml format:

using (var c = new System.Net.Mail.SmtpClient.SmtpClient()
{
    DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory,
    PickupDirectoryLocation = "c:\\temp"
})
{
    var mail = new MailMessage("someone@example.com", "someonelse@example.com", "Very important", "No, just kidding");
    c.Send(mail);
}
Anders Abel
  • 67,989
  • 17
  • 150
  • 217