Good day.

I use SmtpClient to send mail. I need to send an email in cp1251 encoding. I tried to prescribe the title manually:

m.SubjectEncoding = Encoding.Default; m.BodyEncoding = Encoding.Default; m.Headers["Content-type"] = "text/plain; charset=windows-1251"; 

but to no avail.

Can you please tell me how this can be done?

thank

  • Are you sure that Encoding.Default is exactly cp1251? - VladD
  • Even specify the cp1251 encoding there, the result will not change - Leonard Bertone

2 answers 2

Not every system has a pre-installed Windows-1251 encoding (Cyrillic), and even if there is one, it’s far from the fact that it is installed by default. Therefore, I advise you to transfer the client \ server to UTF-8 . Those. You set the Encoding.Default Encoding.Default (the default is taken from the ANSI code page of the operating system), you can conduct an experiment - display the name of the current encoding, for example:

 Encoding.Default.EncodingName 

    or it can use Encoding. GetEncoding (1251);

    • Encoding cp1251 = Encoding.GetEncoding (1251); m.SubjectEncoding = cp1251; // Encoding.Default; m.BodyEncoding = cp1251; // Encoding.Default; m.Headers ["Content-type"] = "text / plain; charset = windows-1251"; --- does not work - Leonard Bertone
    • does not work, tried. but thanks for the reply - Leonard Bertone