C# 使用System.Net.Mail.SmtpClient发送的电子邮件的字体大小

C# 使用System.Net.Mail.SmtpClient发送的电子邮件的字体大小,c#,asp.net,smtp,smtpclient,system.net.mail,C#,Asp.net,Smtp,Smtpclient,System.net.mail,我有一个经过广泛测试的ASP.NETWeb应用程序。其中一部分使用System.Net.Mail.SmtpClient自动发送电子邮件。在测试过程中,从各种Windows7机器发送电子邮件,并使用合理的字体大小进行格式化。顺便说一句,我没有在代码中设置字体大小。现在应用程序正在生产中,第一封电子邮件以非常小的字体发送,用户希望增加字体大小。我当然可以硬编码字体大小,但我更愿意理解这里发生了什么。什么决定字体大小?是SmtpClient中的某个内容,还是SMTP服务器上的某个设置,还是什么?下面是

我有一个经过广泛测试的ASP.NETWeb应用程序。其中一部分使用System.Net.Mail.SmtpClient自动发送电子邮件。在测试过程中,从各种Windows7机器发送电子邮件,并使用合理的字体大小进行格式化。顺便说一句,我没有在代码中设置字体大小。现在应用程序正在生产中,第一封电子邮件以非常小的字体发送,用户希望增加字体大小。我当然可以硬编码字体大小,但我更愿意理解这里发生了什么。什么决定字体大小?是SmtpClient中的某个内容,还是SMTP服务器上的某个设置,还是什么?下面是发送电子邮件的代码。TemplateEditor是页面上的AjaxControlToolkit.HTMLEditor控件。AttyParaMessageBody是包含电子邮件正文的变量。我们的用户使用的是带Outlook 2010的Windows 7

string AttyParaMessageBody = TemplateEditor.Content;
LHEmail.SendEmail(LHClassLibrary.LHConfigurationManager.AppSettings["ApprovedNewVersionLHEmailSubject"].ToString(), AttyParaMessageBody, AttyParaAddressees, CurrentLitHoldDetails.ResponsibleAttorney.Email, LHClassLibrary.LHConfigurationManager.AppSettings["EmailCCList"].ToString() + ";" + tbEmails.Text);

public static void SendEmail(string subject, string body, string to, string from, string cc)
    {
        SendEmail(subject, body, to, from, cc, "", "", MailPriority.High);
    }

public static void SendEmail(string subject, string body, string to, string from, string cc, string bcc, string fileName, MailPriority Priority)
    {

        MailMessage msgMail = new MailMessage();
        SmtpClient emailClient = new SmtpClient();
        try
        {
            msgMail = BuildMessage(subject, body, to, cc, bcc, from, fileName, Priority);
            emailClient.Send(msgMail);
        }
        catch (Exception ex)
        {
            string exception = ex.ToString();
        }
        finally
        {
            msgMail.Dispose();
        }
    }

private static MailMessage BuildMessage(string subject, string body, string to, string cc, string bcc, string from, string fileName, MailPriority Priority)
    {
        MailMessage msgMail = new MailMessage();

        if (!to.Equals(string.Empty))
        {
            //format emails for .NET 4.0 version
            string[] toAddressList = to.Split(';');

            //Loads the To address field 
            foreach (string toaddress in toAddressList)
            {
                if (toaddress.Length > 0)
                {
                    msgMail.To.Add(toaddress);
                }
            }

            //optional args
            //format emails for .NET 4.0 version
            if (!cc.Equals(string.Empty))
            {
                string[] ccAddressList = cc.Split(';');

                //Loads the Cc address field 
                foreach (string ccaddress in ccAddressList)
                {
                    if (ccaddress.Length > 0)
                    {
                        msgMail.CC.Add(ccaddress);
                    }
                }
            }
            if (!bcc.Equals(string.Empty))
            {
                string[] bccAddressList = bcc.Split(';');

                //Loads the Bcc address field 
                foreach (string bccaddress in bccAddressList)
                {
                    if (bccaddress.Length > 0)
                    {
                        msgMail.Bcc.Add(bccaddress);
                    }
                }
            }
            if (!fileName.Equals(string.Empty))
                msgMail.Attachments.Add(new Attachment(fileName));

            msgMail.Priority = Priority;
            msgMail.From = ((from == null) || (from.Equals(string.Empty))) ? new MailAddress("LitHold@kramerlevin.com", "Litigation Hold") : new MailAddress(from, "Litigation Hold");
            msgMail.Subject = subject;
            msgMail.Body = body;
            msgMail.IsBodyHtml = true;

        }
        else { throw new SmtpFailedRecipientException("Failed to provide destination address"); }
        return msgMail;
    }

根据我的经验,当我需要格式化将通过SMTP发送的电子邮件内容时,在设置内容变量的值时,我将使用HTML标记。例如:

String content = "<h2>Thank you for your e-mail</h2><font size=4>We appreciate your feedback.<br/> We will process your request soon</font><br/>Regards.";
String content=“感谢您的电子邮件我们感谢您的反馈。
我们将很快处理您的请求。
如果您的内容将在代码隐藏中设置,那么您可以使用上述方法


希望能有所帮助。

Koo-感谢您的意见。我最终让用户承认他剪切并粘贴了Word中的内容,这就是造成字体大小混乱的原因。他被告知从现在开始使用Ajax控件的“从Word粘贴”功能。