读取XML 发送网页版邮件
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 发送网页版邮件的更多相关文章
- 使用JavaMail发送邮件-从FTP读取图片并添加到邮件正文发送
业务分析: 最近工作需要,需要从FTP读取图片内容,添加到邮件正文发送.发送邮件正文,添加附件采用Spring的MimeMessageHelper对象来完成,添加图片也将采用MimeMessageHe ...
- 用requests登录微信网页版,并接收发送消息
首先,网页版微信登录大致分为以下几个流程(都是大家可以通过抓包得到): 1.登陆主页后,会生成一个UUID,这是个用户标识,在后面请求二维码会用到 def get_uuid(self): '''获取u ...
- spider-web 是爬虫的网页版,使用xml配置
spider-web 是爬虫的网页版,使用xml配置,支持大部分页面的爬取,支持爬取内容的保存.下载等. 其中配置文件格式为: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...
- xml数据发送请求,读取xml
# coding:utf-8 import requests url = "http://httpbin.org/post" # python3字符串换行,在右边加个反斜杠 bod ...
- wechat 网页版通信全过程
想要记录总结一下自己在这个小项目中所遇到的坑,以及解决问题的思路. 首先我觉得这个小项目挺有实际市场的,市场上有一定的需求量,这个就是驱动力吧.这个小项目的关键点是wechat网页版通信全过程,讲真挺 ...
- JavaScript之简易http接口测试工具网页版
简易http接口测试工具网页版,支持get.post请求,支持json格式消息体,form表单暂不支持. httpClient.html <!DOCTYPE html> <html ...
- Ajax读取XML和JSON数据
Ajax从服务器获取的数据都是字符串,但是通过不同的解析,可以解析为XML或者JSON. 一般来说.使用XML格式的数据比较通用,但是服务器和客户端解析起来都比较复杂一些;而使用JSON语句话,服务端 ...
- ASP.NET MVC 学习笔记-2.Razor语法 ASP.NET MVC 学习笔记-1.ASP.NET MVC 基础 反射的具体应用 策略模式的具体应用 责任链模式的具体应用 ServiceStack.Redis订阅发布服务的调用 C#读取XML文件的基类实现
ASP.NET MVC 学习笔记-2.Razor语法 1. 表达式 表达式必须跟在“@”符号之后, 2. 代码块 代码块必须位于“@{}”中,并且每行代码必须以“: ...
- 命令行发送SMTP协议邮件(163邮箱)
这里我们用163邮箱为例子,借助命令行发送smtp邮件 1.连接服务器 在终端上输入:telnet smtp.163.com 25 回车,然后就连接了服务器的25端口,成功会输出 220 163.co ...
随机推荐
- sublime 工具构建
1 Sublime Text 3 配置react语法校验 原文地址:https://segmentfault.com/a/1190000004369542?_ea=585496 终端安装 npm in ...
- 移动web app 中的meta 标签
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scal ...
- sql: 去除数据库表中tab、空格、回车符等特殊字符的解决方法
去除tab.空格.回车符等使用replace语句 按照ASCII码, SELECT char(64) 例如64 对应 @,则select REPLACE('abc@qq.com',char(64),' ...
- ZeroC Ice 暂记
摘自: http://weibo.com/p/1001603869896789339575 原文地址: http://www.oschina.net/question/865233_242146 吴治 ...
- Mbps、Kbps、bps、MB、KB
1:运营商带宽衡量单位: Mbps:百万位每秒 kbps:千位每秒 bps:位每秒 b:bit,比特 1Mbps=1000kbps=1,000,000bps 这些单位通常用来表示每秒传输的二进制位 2 ...
- 墨卡托投影C#实现
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- python学习:环境搭建
1.图解eclipse环境下安装python3.x插件支持:http://www.tuicool.com/articles/M3Afyu 其中如果 然后,选择Add按钮,Name:Python3,Lo ...
- mysql自动添加最后修改时间
字段不为空 NOT NULL 类型 :timestamp 默认值 :CURRENT_TIMESTAMP
- shellinabox基于web浏览器的终端模拟器
1. Shellinabox介绍 Shellinabox 是一个利用 Ajax 技术构建的基于 Web 浏览器的远程终端模拟器,也就是说安装了该软件之后,服务器端不需要开启 ssh服务,通过 Web ...
- Apache ab压力测试时出现大量的错误原因分析
最近有一个测试任务,是测试nginx的并发请求到底能够达到多少的, 于是就用ab工具对其进行压力测试. 这压力测试一执行,问题就来了:发起10000次请求,并发100,错误的情况能达到30%--50% ...