开发者

Some email clients do not display html emails sent from c#

I have a program that sends out HTML emails using c# and System.Net.Mail. The majority of the emails are received correctly, but some recipients are reporting getting an email that looks to me like the encoding. They report that HTML emails sent to them from our users via outlook look correct.

Below is the code I use, I added the "mm.BodyEncoding = System.Text.Encoding.UT开发者_高级运维F8;" to try and fix it, I was not setting this value at all before, which I think defaults to ASCII encoding. This is pretty difficult to debug as I can not recreate the error.

public List<string> Send()
        {
            List<string> Errors = new List<string>();

            try
            {
                MailMessage mm = new MailMessage();
                if (HTMLBody)
                {
                    mm.IsBodyHtml = true;
                    mm.BodyEncoding = System.Text.Encoding.UTF8;
                }
                if (ReplyTo != "")
                {
                    mm.ReplyToList.Add(ReplyTo);
                }
                mm.Body = this.Body;
                mm.Subject = this.Subject;
                mm.From = new System.Net.Mail.MailAddress(this.Sender);
                foreach (string address in this.Recipients.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    try
                    {
                        mm.To.Add(address);
                    }
                    catch (FormatException)
                    {
                        Errors.Add("Invalid Email Address Format:" + address);
                    }

                }
                foreach (string address in BlindCC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    try
                    {
                        mm.Bcc.Add(address);
                    }
                    catch (FormatException)
                    {
                        Errors.Add("Invalid Email Address Format:" + address);
                    }
                }
                SmtpClient smtp = new SmtpClient(SMTPServer);
                foreach (string Attach in Attachments)
                {
                    mm.Attachments.Add(new Attachment(Attach));
                }
                try
                {
                    smtp.Send(mm);
                }
                catch (SmtpException ex)
                {
                    Errors.Add(ex.Message);
                }
            }
            catch (Exception ex)
            {
                Errors.Add(ex.ToString());
            }

            return Errors;
        }

The complaining recipient gets something that looks like this:

Subject: 01/21/2011 Weekly Update Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: base64

To: Undisclosed recipients:;

PGJhc2UgaHJlZj0iaHR0cDovL3d3dy5tdXR1YWxtZWQuY29tL2VtYWlscy8iIC8+ PGh0bWw+PCEtLSBJbnN0YW5jZUJlZ2luIHRlbXBsYXRlPSIvVGVtcGxhdGVzL3Rl bXBsYXRlLmR3dCIgY29kZU91dHNpZGVIVE1MSXNMb2NrZWQ9ImZhbHNlIiAtLT4N CjxoZWFkPg0KPG1ldGEgaHR0cC1lcXVpdj0iQ29udGVudC1UeXBlIiBjb250ZW50

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜