我可以让Web应用程序使用Windows任务计划程序发送自动电子邮件.现在我想使用我为发送电子邮件而编写的以下方法发送HTML格式的电子邮件.
我的代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
SmtpClient sc = new SmtpClient("mail address");
MailMessage msg = null;
try
{
msg = new MailMessage("xxxx@gmail.com",
"yyyy@gmail.com", "Message from PSSP System",
"This email sent by the PSSP system");
sc.Send(msg);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (msg != null)
{
msg.Dispose();
}
}
}
Run Code Online (Sandbox Code Playgroud)
怎么做?我只想在电子邮件中添加一些带有一个链接和一个图像的粗体文本.
是否有更好的方法在C#中生成HTML电子邮件(通过System.Net.Mail发送),而不是使用Stringbuilder执行以下操作:
string userName = "John Doe";
StringBuilder mailBody = new StringBuilder();
mailBody.AppendFormat("<h1>Heading Here</h1>");
mailBody.AppendFormat("Dear {0}," userName);
mailBody.AppendFormat("<br />");
mailBody.AppendFormat("<p>First part of the email body goes here</p>");
Run Code Online (Sandbox Code Playgroud)
等等等等?