Reputation: 10376
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!
Upvotes: 4
Views: 2232
Reputation: 10376
About my second question found this, and it`s helps
For encoding issues I choose to send mails with subjects in english only...
Upvotes: 0
Reputation: 126
The better solution is to create a structure or an automation that impse to system different encodings following the receiver format:
and so on.
Upvotes: 1