Iam using Amazon SES SendRawEmail API hence i need a MailMessage as a Memorystream.
I have found several answers to the MailMessage to MemoryStream issue here on stackoverflow.
Solution 1: Using the one that uses private methods it results in wrong encoding of parts of the email: https://stackoverflow.com/a/8826833
Solution 2: No Encoding problems using this solution where you send to a pickup directory and then read it back in: https://stackoverflow.com/a/14350088
I very much dislike the fact that i need to write to a temporary file to make this work correctly. Does anyone have any idea how the pure MemoryStream solution can mess up some of the encoding.
The mail message iam testing with is this:
var mailMessage = new MailMessage();
mailMessage.Subject = "HEADER WITH SPECIAL ÆØÅ";
mailMessage.Body = "TEST";
Attachment att = new Attachment(@"C:\AttachmentWithSpecial ÆØÅ.pdf");
mailMessage.Attachments.Add(att);
mailMessage.From = new MailAddress("test@test.com", "NameÆØÅ");
mailMessage.To.Add(new MailAddress("test@test.com", "NameÆØÅ"));
To summarize:
- If i send this message with standard SMTP it looks good.
- If i send it using SendRawEmail it looks good if i generated the memorystream by using solution 2
- If i send it using SendRawEmail it has encoding issues if i generated the memorystream by using solution 1.
With encoding issues i mean 'ø' showing up as