我正在發送一封包含C#的電子郵件,並硬編碼將其包含在我的正文中所需的所有數據。硬編碼文本和格式
但是我需要改變一些段落(簽名)的一些字體。我需要將簽名的顏色更改爲灰色,並將字體大小更改爲較小的大小。這可以做硬編碼嗎?
mm.Body = "TEXT TEXT TEXT"+
"\r\n different font and color";
我正在發送一封包含C#的電子郵件,並硬編碼將其包含在我的正文中所需的所有數據。硬編碼文本和格式
但是我需要改變一些段落(簽名)的一些字體。我需要將簽名的顏色更改爲灰色,並將字體大小更改爲較小的大小。這可以做硬編碼嗎?
mm.Body = "TEXT TEXT TEXT"+
"\r\n different font and color";
設置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;
而且也試試這個:
msg.BodyFormat = MailFormat.Html;
嗨,你需要將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
使用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);
}
}
}
}
mm.Body = "<p>TEXT TEXT TEXT</p>"+
"<p style='color: green; font-size:16px'>different font and color</p>";
mm.IsBodyHtml = true;
什麼是類'mm'的? – wasyl
您需要設置HTML正文。將MailMessage.IsBodyHtml設置爲true。然後,您可以使用內聯樣式和樣式標籤進行簡單的HTML格式設置。 –
對不起。 Class mm是郵件消息。 –