.net - C# MailMessage to stream - encoding issue -


iam using amazon ses sendrawemail api hence need mailmessage memorystream.

i have found several answers mailmessage memorystream issue here on stackoverflow.

solution 1: using 1 uses private methods results in wrong encoding of parts of email: https://stackoverflow.com/a/8826833

solution 2: no encoding problems using solution send pickup directory , read in: https://stackoverflow.com/a/14350088

i dislike fact need write temporary file make work correctly. have idea how pure memorystream solution can mess of encoding.

the mail message iam testing this:

var mailmessage = new mailmessage(); mailmessage.subject = "header 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 send message standard smtp looks good.
  • if send using sendrawemail looks if generated memorystream using solution 2
  • if send using sendrawemail has encoding issues if generated memorystream using solution 1.

with encoding issues mean 'ø' showing

enter image description here

did try explicitly specify encoding subject / body , mailaddress?

i guess when .net writes mails folder can somehow define right encoding (or maybe file reader somehow can find right encoding convert data). , in memory in default encoding, not work you.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -