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<tos.Length;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 网页但是要写在 <![CDATA[  内容  ]]>  之间,如下例子:

<?xml version="1.0" encoding="utf-8" ?>

<MailTemplate>
<mail>
<!-- 请勿修改 -->
<name>Delay</name>
<!-- 可配置 -->
<title></title>
<!-- 可配置 -->
<content>

<![CDATA[

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style>
body,table,td,div,p,form{
padding:0px;
border-width:0px;
font-family: "Tahoma","Arial", "Verdana", "Helvetica", "sans-serif";
color:#414141;
font-size:14px;
}
.colorFFF{
color:#FFF;
}
.colorff6602{
color:#ff6602;
}
</style>
</head>

<body>
<div class="mailForm">
<div class="mailTitle colorFFF fontbold">标题</div>
<p>尊敬的 <span class="fontbold fontsize16">$Name$</span>,您好!</p>
<p>内容</p>
<p>内容</p>

<p>。。。。。。</p>
<p>==================================</p>

<p>==================================</p>
<br />
<p class="lineheight">Best Regards<br />
XXX团队<br />
$DateTime$
</p>
</div>
</body>
</html>
]]>

</content>
<!-- 可配置 -->
<to>$Manager$,$Actor$</to>
<!-- 可配置 -->
<cc>$Admin$</cc>
</mail>
</MailTemplate>

读取XML 发送网页版邮件的更多相关文章

  1. 使用JavaMail发送邮件-从FTP读取图片并添加到邮件正文发送

    业务分析: 最近工作需要,需要从FTP读取图片内容,添加到邮件正文发送.发送邮件正文,添加附件采用Spring的MimeMessageHelper对象来完成,添加图片也将采用MimeMessageHe ...

  2. 用requests登录微信网页版,并接收发送消息

    首先,网页版微信登录大致分为以下几个流程(都是大家可以通过抓包得到): 1.登陆主页后,会生成一个UUID,这是个用户标识,在后面请求二维码会用到 def get_uuid(self): '''获取u ...

  3. spider-web 是爬虫的网页版,使用xml配置

    spider-web 是爬虫的网页版,使用xml配置,支持大部分页面的爬取,支持爬取内容的保存.下载等. 其中配置文件格式为: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...

  4. xml数据发送请求,读取xml

    # coding:utf-8 import requests url = "http://httpbin.org/post" # python3字符串换行,在右边加个反斜杠 bod ...

  5. wechat 网页版通信全过程

    想要记录总结一下自己在这个小项目中所遇到的坑,以及解决问题的思路. 首先我觉得这个小项目挺有实际市场的,市场上有一定的需求量,这个就是驱动力吧.这个小项目的关键点是wechat网页版通信全过程,讲真挺 ...

  6. JavaScript之简易http接口测试工具网页版

    简易http接口测试工具网页版,支持get.post请求,支持json格式消息体,form表单暂不支持. httpClient.html <!DOCTYPE html> <html ...

  7. Ajax读取XML和JSON数据

    Ajax从服务器获取的数据都是字符串,但是通过不同的解析,可以解析为XML或者JSON. 一般来说.使用XML格式的数据比较通用,但是服务器和客户端解析起来都比较复杂一些;而使用JSON语句话,服务端 ...

  8. ASP.NET MVC 学习笔记-2.Razor语法 ASP.NET MVC 学习笔记-1.ASP.NET MVC 基础 反射的具体应用 策略模式的具体应用 责任链模式的具体应用 ServiceStack.Redis订阅发布服务的调用 C#读取XML文件的基类实现

    ASP.NET MVC 学习笔记-2.Razor语法   1.         表达式 表达式必须跟在“@”符号之后, 2.         代码块 代码块必须位于“@{}”中,并且每行代码必须以“: ...

  9. 命令行发送SMTP协议邮件(163邮箱)

    这里我们用163邮箱为例子,借助命令行发送smtp邮件 1.连接服务器 在终端上输入:telnet smtp.163.com 25 回车,然后就连接了服务器的25端口,成功会输出 220 163.co ...

随机推荐

  1. Java-生成指定长度验证码的一种简单思路

     前言:以前做过的一个项目,刚开的时候始验证码是在前端生成前端验证的,后来觉得不靠谱,另外就是找回密码的功能也需要发送邮件和短信的验证码,所以,验证码就必须在后端生成并且保存到应用会话中才行了!所以, ...

  2. C#中用RichTextBox实现图文混排和保存的例子

    using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; us ...

  3. C#多文档程序中如何只打开一个子窗口

    using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; na ...

  4. css secrets----multiple borders

    原始文档: https://www.zybuluo.com/freeethy/note/193574 box-shadow solution 只能实现solid border box-shadow表现 ...

  5. Java日志——2016.6.3

    1)二维数组的静态初始化:                int[][] arr = new int[][] { {1,2,3}, {4,5}, {6,7}} 2)杨辉三角: /** *    需求: ...

  6. 第六百一十天how can I 坚持

    今天又去了趟ccrs,终于把环境打起来了,下午就去中关村了,回来的时候还忘了带电脑电源,明天还得去fh,也是醉了.. 好困啊.得睡觉了,项目感觉也不是多难,不过代码还得好好熟悉熟悉.加油吧.

  7. 一些对数学领域及数学研究的个人看法(转载自博士论坛wcboy)

    转自:http://www.math.org.cn/forum.php?mod=viewthread&tid=14819&extra=&page=1 原作者: wcboy 现在 ...

  8. 照片元数据信息以及在照片中写入gps信息

    /// 照片元数据编码 在下面的文章里,可以看到图片所有的元数据定义信息 https://msdn.microsoft.com/zh-cn/library/system.drawing.imaging ...

  9. Shell 的变量功能

    搜寻路径PATH(系统预设变量) 执行命令时,系统透过PATH得路径顺序搜寻指令,如果再搜寻完后还找不到该指令,就会打印错误讯息[command not fount].   环境变量 进入shell之 ...

  10. ajaxfileupload.js的简单使用

    上传文件 未选择任何文件 引入 <script src="../javaScript/ajaxfileupload.js"></script> <bu ...