In my project, I am using ImapClient to download email and save to disk in Outlook msg format. At a later time, I processing these saved msg files by loading back into a MailMessage object. I have no problems processing the msg files and extracting the attachments and contents.
However, for emails that I cannot process for whatever reason (lets say a password protected attachment that I cannot open) i forward this email back to the recipient as an attachment to a new MailMessage and send via SmtpClient.
The code I am using to do this is as follows (as per a previous thread post):
MailMessage message = new MailMessage(“from”, “to”, “subject”, “body”);
// Load the error email
using (var error = MailMessage.Load(“PathToMsgFile”))
// Save as eml
MemoryStream ms = new MemoryStream();
var attachment = new Attachment(ms, “Test”, “message/rfc822”);
From what I can tell of all of the debugging I have been doing is that the conversion from MSG to EML does not appear to be producing a compliant EML file. I have tested saving EML to a file and often these files won’t show any attachments if there are any whilst they are present in the MSG file. The resultant EML files also take a long time to open in outlook.
I have also tested this on my production server running Windows Server 2008 R2 and have found that the call to SmtpClient.Send hangs if the content type is set to message/rfc822, if I remove this and just attached a .eml file this is no problem (however the attachment has the same symptoms as described above).