You can use System.Net.Mail.Attachment.CreateAttachmentFromString
without specifying the encoding like so Attachment.CreateAttachmentFromString(content, name)
, what encoding will be used to encode content string in this case?
Asked
Active
Viewed 508 times
-1

Mykhailo Seniutovych
- 3,527
- 4
- 28
- 50
-
I'm not sure, but I think the same as your machine, for example, I live in Germany, my encoding is Windows-1252. I use to had problems with this because the UTF 8 were not working. By the way, you should use MimeKit, amazing and free library to handle emails. – Nekeniehl Feb 13 '18 at 15:27
1 Answers
3
According to the documentation, it's either ASCII or UTF-8:
If the content is in ASCII format then the character encoding is set to ASCII. For all other formats, the character encoding is set to utf-8. The default media type is plain text.
If the content is not in ASCII format and the encoding is null, utf-8 encoding is used.

halfer
- 19,824
- 17
- 99
- 186

Daniel A. White
- 187,200
- 47
- 362
- 445
-
https://referencesource.microsoft.com/#System/net/System/Net/mail/Attachment.cs,ef94439e5abc1a40 backs that up – bartonjs Feb 13 '18 at 15:29
-
if I do it like so `string content = "some hardcoded string"; Attachment.CreateAttachmentFromString(content, name)` what encoding will be used? – Mykhailo Seniutovych Feb 13 '18 at 15:32
-