Pregunta

I`m trying to send e-mail via c# and use the following code:

public static bool SendSMTPMail(string smtphost, int smtpport, string smtplogin, string smtppassword, string from, string to, string subject, string body, bool isHtml)
{
  try
  {               
    using (MailMessage message = new MailMessage(from, to, subject, body))
    {
      message.IsBodyHtml = isHtml;
      message.SubjectEncoding = System.Text.Encoding.UTF8;
      message.BodyEncoding = System.Text.Encoding.UTF8;

      SmtpClient mailClient = new SmtpClient(smtphost, smtpport);
      mailClient.EnableSsl = false;
      mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
      mailClient.Credentials = new NetworkCredential(smtplogin, smtppassword);

      mailClient.Send(message);
      return true;
    }
  }
  catch
  {
    return false;
  }
}

It works fine, when mails recieved in Windows, but when user trying to read them in MacOS - subject header is in wrong encoding. If I set subject encoding to Windows-1251, it works good, but only for cyrillic subjects, and I`m going to send asian too...

How can I send emails using pure Unicode?

And the second question - if I`ll add any attachment to the mail, it will be added with extra files - "filelist.xml" and "header.htm".

How to get rid of them?

Thaks!

¿Fue útil?

Solución 2

About my second question found this, and it`s helps

For encoding issues I choose to send mails with subjects in english only...

Otros consejos

The better solution is to create a structure or an automation that impse to system different encodings following the receiver format:

  • generic utf8
  • iso xxx for cyrillic
  • iso xxy for chinese

and so on.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top