简体   繁体   English

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

[英]Font size for an email sent using System.Net.Mail.SmtpClient

I have an ASP.Net web application that's been tested extensively. 我有一个经过广泛测试的ASP.Net Web应用程序。 One portion of it sends an email automatically using System.Net.Mail.SmtpClient. 其中一部分使用System.Net.Mail.SmtpClient自动发送电子邮件。 During testing, from various Windows 7 machines, the emails were sent and were formatted with a reasonable font size. 在测试期间,通过各种Windows 7计算机发送了电子邮件,并以合理的字体大小对其进行了格式化。 I don't set the font size in the code, BTW. 我没有在代码中设置字体大小,顺便说一句。 Now that the application's in production, the first email got sent in a very small font and the users want the font size increased. 现在该应用程序已经投入生产,第一封电子邮件以非常小的字体发送,用户希望字体大小增加。 I can hard-code the font size of course, but I'd prefer to understand what's going on here. 我当然可以对字体大小进行硬编码,但是我更希望了解这里发生的情况。 What determines the font size? 什么决定字体大小? Is it something in the SmtpClient, or some setting on the SMTP server, or what? 是SmtpClient中的内容,还是SMTP服务器上的某些设置,还是什么? Below is the code that sends the email. 以下是发送电子邮件的代码。 TemplateEditor is an AjaxControlToolkit.HTMLEditor control on the page. TemplateEditor是页面上的AjaxControlToolkit.HTMLEditor控件。 AttyParaMessageBody is the variable that contains the email body. AttyParaMessageBody是包含电子邮件正文的变量。 Our users are on Windows 7 with Outlook 2010. 我们的用户使用带有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;
    }

From my experience, when i need to format my e-mail content that will be sent through SMTP, i will use HTML tag when i set value for the content variable. 根据我的经验,当我需要格式化将通过SMTP发送的电子邮件内容时,当我为content变量设置值时,我将使用HTML标记。 For example: 例如:

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.";

If ur content will be set in the code behind, then u can using the above method. 如果将在后面的代码中设置您的内容,则可以使用上述方法。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用System.Net.Mail.SmtpClient将电子邮件发送到通讯组列表 - Sending email to a distribution list using System.Net.Mail.SmtpClient 如何在Xamarin中使用System.Net.Mail.SmtpClient发送邮件 - How to send a mail in Xamarin using System.Net.Mail.SmtpClient 使用System.Net.Mail.SmtpClient,更改SMTP FROM电子邮件地址 - Using System.Net.Mail.SmtpClient, change the SMTP FROM email address 无法使用 System.Net.Mail.SmtpClient 将 email 发送到其他域 - Unable to send email to other domains using System.Net.Mail.SmtpClient System.Net.Mail.SmtpClient 在 4.7 中过时了吗? - Is System.Net.Mail.SmtpClient obsolete in 4.7? 第三方与System.Net.Mail.SmtpClient - Third-party vs System.Net.Mail.SmtpClient 发送到 System.Net.Mail.SmtpClient 等文件夹 - Send to folder like System.Net.Mail.SmtpClient 如何使用TLS和System.Net.Mail.SMTPCLient连接到googlemail.com? - How can I connect to googlemail.com using TLS and System.Net.Mail.SMTPCLient? System.Net.Mail.SmtpClient 在发送电子邮件时使用什么类型的身份验证? - What type of authentication is System.Net.Mail.SmtpClient using when sending emails? 使用TLS和SmtpAuth在.Net 4 / C#中发送带有System.Net.Mail.SmtpClient的电子邮件,可在本地使用,但不能在生产服务器上运行(win 2008 r2) - Sending email with System.Net.Mail.SmtpClient in .Net 4/C# with TLS and SmtpAuth, works locally but not on production server(win 2008 r2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM