2016-03-08 139 views
3

我面臨發送文本的HTML標記的郵件郵寄的問題。起初,我RTF轉換爲HTML發送富文本電子郵件

string GetHtmlContent(string someRTFtext) 
{ 
    RichEditDocumentServer server = new RichEditDocumentServer(); 
    server.RtfText = someRTFtext; 
    server.Options.Export.Html.CssPropertiesExportType = DevExpress.XtraRichEdit.Export.Html.CssPropertiesExportType.Inline; 
    server.Options.Export.Html.DefaultCharacterPropertiesExportToCss = true; 
    server.Options.Export.Html.EmbedImages = true; 
    server.Options.Export.Html.ExportRootTag = DevExpress.XtraRichEdit.Export.Html.ExportRootTag.Body; 

    return server.HtmlText; 
} 

這個方法返回我

<body> 
<style type="text/css"> 
    .cs2E86D3A6{text-align:center;text-indent:0pt;margin:0pt 0pt 0pt 0pt} 
    .cs88F66593{color:#800080;background-color:transparent;font-family:Arial;font-size:8pt;font-weight:bold;font-style:normal;} 
</style> 
<p class="cs2E86D3A6"><span class="cs88F66593">Форматированый текст</span></p></body> 

但此帖一簡單的文本,沒有任何選擇,字體等 這裏是發送

的方法
try 
{ 
    string login = ConfigurationManager.AppSettings["EmailLogin"]; 
    string password = ConfigurationManager.AppSettings["EmailPassword"]; 

    MailMessage mail = new MailMessage(); 
    mail.From = new MailAddress(login); 

    if (lbStudents.Items.Count == 0) 
     MessageBox.Show("Error.", "Sending massage", MessageBoxButtons.OK, MessageBoxIcon.Information); 

    foreach (SmallStudent student in lbStudents.Items) 
    { 
     mail.To.Add(new MailAddress(student.Email)); 
    } 

    if (txtSubject.Text.Trim() == String.Empty) 
    { 
     MessageBox.Show("Error.", "Sending massage", 
     MessageBoxButtons.OK, MessageBoxIcon.Information); 
     return; 
    } 

    mail.Subject = txtSubject.Text.Trim(); 
    mail.Body = GetHtmlContent(rtfEditor.DocumentRtf); 
    mail.IsBodyHtml = true; 
    mail.BodyEncoding = Encoding.UTF8; 

    SmtpClient client = new SmtpClient(); 
    client.Host = "smtp.gmail.com"; 
    client.Port = 587; 
    client.EnableSsl = true; 
    client.Credentials = new NetworkCredential(login.Split('@')[0], password); 
    client.DeliveryMethod = SmtpDeliveryMethod.Network; 
    client.Send(mail); 
    mail.Dispose(); 
} 
catch (Exception exception) 
{ 
    MessageBox.Show("Exception: " + exception.Message, 
        "Sending massage", 
        MessageBoxButtons.OK, 
        MessageBoxIcon.Information); 
} 
+0

我不確定