using System.Net.Mail;
using System.IO;

SmtpClient mySC 
= new SmtpClient();
mySC.DeliveryMethod 
= SmtpDeliveryMethod.Network;//指定电子邮件发送方式
mySC.Host = "smtp.from.com";//指定SMTP服务器
mySC.Credentials = new System.Net.NetworkCredential("myAccount","myPassword");//用户名和密码

MailMessage myMM 
= new MailMessage("from@from.com","to@to.com");
myMM.Subject 
= title;//主题
myMM.Body = content;//内容
myMM.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
myMM.IsBodyHtml = true;//设置为HTML格式
myMM.Priority = MailPriority.High;//优先级
try
{
    mySC.Send(myMM);
//发送邮件
}
catch (Exception error)
{
    
using (StreamWriter sw = new StreamWriter(logPath, true, System.Text.Encoding.UTF8))
    {
        
//写入错误日志
        sw.WriteLine(error.ToString());
        sw.Close();
    }
}

相关文章:

  • 2022-01-23
  • 2021-05-28
  • 2021-11-28
  • 2021-05-17
  • 2022-02-19
  • 2022-02-08
  • 2022-12-23
  • 2022-01-22
猜你喜欢
  • 2022-12-23
  • 2022-01-26
  • 2021-12-02
  • 2021-08-24
  • 2021-05-19
  • 2022-01-22
  • 2022-12-23
相关资源
相似解决方案