When i send mails with .NET SmtpClient, i have noticed the content transfer encoding is set to base64 when i check the source code of the mail.
I need to set it to Quoted-printable. How can i achieve this ? Thanks in advance
public virtual MailMessage GetMailMessage(string body, string from, string [] user_emails, string [] back_office_emails, string subject)
{
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
message.From = new MailAddress(from);
foreach (string email in user_emails)
{
message.To.Add(new MailAddress(email));
}
if (back_office_emails != null)
{
foreach (string email in back_office_emails)
{
message.Bcc.Add(new MailAddress(email));
}
}
message.Subject = subject;
message.Body = body;
message.BodyEncoding = System.Text.Encoding.UTF8;
return message;
}
protected virtual void SendEmailTemplate(string body, string from, string[] user_emails, string[] back_office_emails, string subject)
{
MailMessage message = GetMailMessage(body, from, user_emails, back_office_emails, subject);
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["SmtpClient"]);
client.Send(message);
}
Solution:
AlternateView plainTextView = AlternateView.CreateAlternateViewFromString(body.Trim(), new ContentType("text/html; charset=UTF-8"));
plainTextView.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
message.AlternateViews.Add(plainTextView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With