Question

I am sending an email with C# and hardcoding all the data needed for this to include in my Body.

However I need to change some fonts of some paragraphs(signature). I need to change the color of the signature to gray and changing the font size to a smaller size. Can this be done hardcoded?

mm.Body = "TEXT TEXT TEXT"+
"\r\n different font and color";
Was it helpful?

Solution

Setting isBodyHtml to true allows you to use HTML tags in the message body:

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;

Read this

And also try this :

msg.BodyFormat = MailFormat.Html;

OTHER TIPS

Hi you need to set IsBodyHtml to true:

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

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

Use htmlbody for setting font and color...

    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);
        }
    }
}

}

mm.Body = "<p>TEXT TEXT TEXT</p>"+
"<p style='color: green; font-size:16px'>different font and color</p>";
mm.IsBodyHtml = true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top