如何使用asp.net C#发送带有内容html标签的邮件?

如何使用asp.net C#发送带有内容html标签的邮件?

问题描述:

可以帮助我使函数使用asp.net C#发送带有内容html标签的邮件吗?

Can help me make function send mail with content html tag using asp.net C# ?

单击此处: ^ ] ]的HTML邮件
Click there: html mail in c#[^]


只是一个提示:电子邮件应具有"Content-Type:text/html";例如,您可以使用标题行之一
Just a hint: the e-mail should have "Content-Type: text/html"; for example, you can have one of the header lines
Content-Type: text/html; charset="utf-8"



—SA



—SA


您可以使用此库发送邮件.
http://higlabo.codeplex.com/ [ ^ ]

You can send mail with this library.
http://higlabo.codeplex.com/[^]

SmtpClient cl = new SmtpClient();
cl.ServerName = "your server name";
cl.Port = 25;
cl.Ssl = false;
SmtpMessage mg = new SmtpMessage();
mg.Subject = "Html mail test";
mg.From = "my_address@mail.com";
mg.To.Add(new MailAddress("address@mail.com"));
//Send by HTML format
SmtpContent ct = new SmtpContent();
ct.LoadHtml("<html><head></head><body>......</body></html>");
mg.Contents.Add(ct);

var rs = cl.SendMail(mg);
//Check mail was sent or not
if (rs.SendSuccessfull == false)
{
    //You can get information about send mail is success or error reason
    var resultState = rs.State;
}