2013-10-28 24 views
1

我正在发送一封包含C#的电子邮件,并硬编码将其包含在我的正文中所需的所有数据。硬编码文本和格式

但是我需要改变一些段落(签名)的一些字体。我需要将签名的颜色更改为灰色,并将字体大小更改为较小的大小。这可以做硬编码吗?

mm.Body = "TEXT TEXT TEXT"+ 
"\r\n different font and color"; 
+0

什么是类'mm'的? – wasyl

+2

您需要设置HTML正文。将MailMessage.IsBodyHtml设置为true。然后,您可以使用内联样式和样式标签进行简单的HTML格式设置。 –

+0

对不起。 Class mm是邮件消息。 –

回答

5

设置isBodyHtml为true,允许你使用HTML标签在邮件正文:

msg = new MailMessage("[email protected]", 
       "[email protected]", "Message from PSSP System", 
       "This email sent by the PSSP system<br />" + 
       "<b>this is bold text!</b>"); 

msg.IsBodyHtml = true; 

Read this

而且也试试这个:

msg.BodyFormat = MailFormat.Html; 
0

嗨,你需要将IsBodyHtml设置为true:

MailMessage msg = new MailMessage(addressFrom, addressTo, subject, body); 
      msg.IsBodyHtml = isBodyHtml; 

body parameter should contain actual body of your mail with style applied 
0

使用htmlbody设置字体和颜色...

namespace mysendemail 
    { 
    class Program 
    { 
     static void Main(string[] args) 
     { 
     SmtpMail oMail = new SmtpMail("TryIt"); 
     SmtpClient oSmtp = new SmtpClient(); 

     // Set sender email address, please change it to yours 
     oMail.From = "[email protected]"; 

     // Set recipient email address, please change it to yours 
     oMail.To = "[email protected]"; 

     // Set email subject 
     oMail.Subject = "test html email from C#"; 

     // Set Html body 
     oMail.HtmlBody = "<font size=5>This is</font> <font color=red><b>a test</b></font>"; 

     // Your SMTP server address 
     SmtpServer oServer = new SmtpServer("smtp.emailarchitect.net"); 

     // User and password for ESMTP authentication, if your server doesn't require 
     // User authentication, please remove the following codes.    
     oServer.User = "[email protected]"; 
     oServer.Password = "testpassword"; 

     // If your smtp server requires SSL connection, please add this line 
     // oServer.ConnectType = SmtpConnectType.ConnectSSLAuto; 

     try 
     { 
      Console.WriteLine("start to send HTML email ..."); 
      oSmtp.SendMail(oServer, oMail); 
      Console.WriteLine("email was sent successfully!"); 
     } 
     catch (Exception ep) 
     { 
      Console.WriteLine("failed to send email with the following error:"); 
      Console.WriteLine(ep.Message); 
     } 
    } 
} 

}

0
mm.Body = "<p>TEXT TEXT TEXT</p>"+ 
"<p style='color: green; font-size:16px'>different font and color</p>"; 
mm.IsBodyHtml = true;