我有一個經過廣泛測試的ASP.Net Web應用程序。它的一部分使用System.Net.Mail.SmtpClient自動發送一封電子郵件。在測試期間,從各種Windows 7機器發送電子郵件並將其格式化爲合理的字體大小。我不會在代碼中設置字體大小,順便說一句。現在應用程序已投入使用,第一封電子郵件以非常小的字體發送,用戶希望增加字體大小。我可以硬編碼字體大小,但我更願意理解這裏發生了什麼。什麼決定字體大小?它是否在SmtpClient中,或SMTP服務器上的某些設置,或什麼?以下是發送電子郵件的代碼。 TemplateEditor是頁面上的AjaxControlToolkit.HTMLEditor控件。 AttyParaMessageBody是包含電子郵件正文的變量。我們的用戶在Windows 7上使用Outlook 2010使用System.Net.Mail.SmtpClient發送的電子郵件的字體大小
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("[email protected]", "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;
}
辜 - 感謝您的意見。我終於讓用戶承認他會從Word中剪切和粘貼他的內容,這正是弄亂字體大小的原因。他從現在起被告知使用Ajax控件的「從Word粘貼」功能。 – Melanie