C#中解析XML文件,以HTML的格式发送邮件?

2024-12-24 22:21:25
推荐回答(1个)
回答1:

解析用using System.Xml;
里面包含了很多简便的方法。
生成html代码你就自己写字符串拼接了,
发邮件用using System.Net.Mail;
try
{
MailAddress from = new MailAddress(cfg.mail_from_email, cfg.mail_from_name); //邮件的发件人
MailMessage mail = new MailMessage();
mail.From = from;
for (int i = 0; i < a.Length; i++)
{
mail.To.Add(a[i]);
}
mail.Subject = cfg.mail_from_Subject + "[" + info[0] + "]";
mail.Body = "

"
+ ""
.....................................你的html代码
+“
******登记表
工号:" + info[21] + "编号:INS-REPORT-MAIL-" + logid + "
";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal;
SmtpClient smtpSender = new SmtpClient(cfg.mail_host);
smtpSender.Credentials = new System.Net.NetworkCredential(cfg.mail_user, cfg.mail_pasw);
smtpSender.UseDefaultCredentials = false;
smtpSender.DeliveryMethod = SmtpDeliveryMethod.Network;
// smtpSender.Send(mail);
smtpSender.SendAsync(mail, "sendMail-" + logid);
}
catch (Exception err)
{
ret = false;
writeLog("线程 [....] 运行 [....] 过程发生错误! 错误反馈:" + err.Message);
}