读取XML 发送网页版邮件
2020-12-13 04:44
YPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
标签:style class c ext http color
DataSet ds = new DataSet();
ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory + "XML\\Mail.xml");
if (ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
if (dt.Rows.Count
> 0)
{
body =
dt.Rows[0]["content"].ToString();
}
}
body = body.Replace("$Name$",
custName).Replace("$DateTime$",
DateTime.Now.ToString("yyyy年MM月dd日")).ToString();
attachment.Name = “附件名字”;
string subject = "邮件主题";
string to= "邮件接收人";
Send(to, subject, body, attachment); //邮件发送
// 一下是Send 方法
public static bool Send(string to, string subject, string body, Attachment
attachment)
{
to = to.Replace(";", ";");
string
from = "163邮箱";
string userName = "163登录名";
string pwd =
"163密码";
string host = "smtp.163.com"; //163邮箱 host
int
port = 25;
MailAddress mailSender = new MailAddress(from);
string[] tos = to.Split(‘;‘);
MailMessage mailMsg = new
MailMessage(from, tos[0], subject, body);
if (tos.Length >
0)
{
for(int i = 1; i
mailMsg.CC.Add(tos[i]);
}
}
mailMsg.IsBodyHtml = true;
mailMsg.Sender = mailSender;
mailMsg.SubjectEncoding = Encoding.UTF8;
mailMsg.BodyEncoding = Encoding.UTF8;
mailMsg.HeadersEncoding =
Encoding.UTF8;
if (attachment != null)
{
mailMsg.Attachments.Add(attachment);
}
new Macrowing.Common.SystemEx.SysException("2");
SmtpClient
client = new SmtpClient(host, port);
client.Credentials = new
NetworkCredential(userName, pwd);
try
{
client.Send(mailMsg);
new
Macrowing.Common.SystemEx.SysException("3");
return true;
}
catch (Exception e)
{
new Macrowing.Common.SystemEx.SysException("4");
Log.WriteEmailSendExcptionLog(e.Message);
}
new
Macrowing.Common.SystemEx.SysException("5");
return false;
}
/// XML 中的mail.xml 配置 、 可复制整个html 网页但是要写在 之间,如下例子:
尊敬的 $Name$,您好!
内容
内容
。。。。。。
==================================
==================================
Best Regards
XXX团队
$DateTime$
]]>
读取XML 发送网页版邮件,搜素材,soscw.com
读取XML 发送网页版邮件
标签:style class c ext http color
原文地址:http://www.cnblogs.com/zhangjinjin/p/3734025.html