locked
MailMessage Encoding RRS feed

  • Question

  • Hi,

    I set the encoding for the mailMessage to Windows-1255, When the message sent the client accepted it as utf-8.
    I wrote the following code  :

     

    using (MailMessage mailMessage = new MailMessage())
    {
    Encoding encoding = Encoding.GetEncoding(1255);
    mailMessage.From = new MailAddress(txtFrom.Text.Trim(), txtFromName.Text, encoding);
    mailMessage.To.Add(
    new MailAddress(txtTo.Text.Trim(), string.Empty, encoding));
    mailMessage.BodyEncoding = encoding;
    mailMessage.SubjectEncoding = encoding;
    mailMessage.Subject = txtSubject.Text;
    mailMessage.Body = txtBody.Text;
    SmtpClient smtp = new SmtpClient(txtHost.Text.Trim(), int.Parse(txtPort.Text.Trim()));
    smtp.UseDefaultCredentials = true;
    smtp.Send(mailMessage);
    }

     

    How can i cause the message to be sent as Windows-1255 encoding ?
    Thnx,
    khalil 

    Thursday, October 21, 2010 8:07 AM

Answers

  • When your mail client encodes the text and sends it away, the bytes are created according to the encoding you chose.

    When the mail is received by some e-mail software (Outlook or Thunderbird for example), the software will decode the bytes (to present them on screen as text) according to the user's preference (UTF-8, ISO-8859-15 etc. or automatically if possible). So, in the general case, you cannot "force" the correct display of your encoding.

    Cristian.

    • Marked as answer by khalil salhi Tuesday, October 26, 2010 7:23 AM
    Friday, October 22, 2010 7:04 PM

All replies

  • Most mail clients offer different character encodings for viewing. The fact that you send your mail with a specific encoding does not guarantee that it will be displayed in that same encoding, just that the text encoding follows a specific standard.

    Cristian.

    Thursday, October 21, 2010 4:26 PM
  • Hi,

    Does it the enconding on the mailmessage is not worked ?

    And what did you mean by " just that the text encoding follows a specific standard." ?

    Thnx,
    khalil
    Friday, October 22, 2010 6:51 PM
  • When your mail client encodes the text and sends it away, the bytes are created according to the encoding you chose.

    When the mail is received by some e-mail software (Outlook or Thunderbird for example), the software will decode the bytes (to present them on screen as text) according to the user's preference (UTF-8, ISO-8859-15 etc. or automatically if possible). So, in the general case, you cannot "force" the correct display of your encoding.

    Cristian.

    • Marked as answer by khalil salhi Tuesday, October 26, 2010 7:23 AM
    Friday, October 22, 2010 7:04 PM