2

我正在发送一封带有 C# 的电子邮件,并对包含在我的正文中所需的所有数据进行硬编码。

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

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

4 回答 4

6

设置isBodyHtml为 true 允许您在消息正文中使用 HTML 标记:

msg = new MailMessage("xxxx@gmail.com",
                "yyyy@gmail.com", "Message from PSSP System",
                "This email sent by the PSSP system<br />" +
                "<b>this is bold text!</b>");

msg.IsBodyHtml = true;

读这个

也试试这个:

msg.BodyFormat = MailFormat.Html;
于 2013-10-28T14:01:03.767 回答
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
于 2013-10-28T14:02:49.127 回答
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 = "test@emailarchitect.net";

        // Set recipient email address, please change it to yours
        oMail.To = "support@emailarchitect.net";

        // 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 = "test@emailarchitect.net";
        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);
        }
    }
}

}

于 2013-10-28T14:03:09.963 回答
0
mm.Body = "<p>TEXT TEXT TEXT</p>"+
"<p style='color: green; font-size:16px'>different font and color</p>";
mm.IsBodyHtml = true;
于 2013-10-28T14:03:11.807 回答