实战篇之实现 OutLook 中以 EDM 形式发送通知邮件
1.写 Html5 的 EDM 模板
EDM 源代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Html5-代码示例</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
img {
border: none;
}
table {
border-spacing: 0;
border-collapse: collapse;
}
td {
word-break: break-word;
-webkit-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
border-collapse: collapse !important;
}
table, tr, td {
padding: 0;
}
.auto-style1 {
height: 28px;
}
</style>
</head>
<body>
<table bgcolor="#f3f4e6" width="900" align="center" border="0" cellspacing="0" cellpadding="0" class="body">
<tbody>
<tr>
<td width="100%">
<table width="100%" height="55" align="center" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td height="55" align="right" bgcolor="#ffc439">
<td>#UserNsame#</td>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
2.邮件发送核心代码
public class MyEmailCode
{
#region 模板获取
/// 获取邮件模板
public static string GetMailTemp(string tempPath, string UserName)
{
StringBuilder content = new StringBuilder();
if (File.Exists(tempPath))
{
using (StreamReader sr = new StreamReader(tempPath, Encoding.GetEncoding("utf-8")))
{
String srLine;
while ((srLine = sr.ReadLine()) != null)
{
content.AppendLine(srLine);
}
content.Replace("#UserName#", UserName);
}
return content.ToString();
}
return null;
}
#endregion
static bool SendEmail(string from, string to, string content, string title, out string message, IList<string> ccs = null, IList<string> bccs = null)
{
Encoding encoding = Encoding.GetEncoding("utf-8");
string strHost = host;
string strAcount = account;
string strPwd = pwd;
string strForm = from;
string strTo = to;
SmtpClient _smtpClient = new SmtpClient();
_smtpClient.Host = strHost;
_smtpClient.Credentials = new System.Net.NetworkCredential(strAcount,strPwd);
_smtpClient.Port = 587;
_smtpClient.EnableSsl = true;
MailMessage _mailMessage = new MailMessage(new MailAddress(strForm, "", encoding),
new MailAddress(strTo, "", encoding));
_mailMessage.Subject = title;
_mailMessage.Body = content;
_mailMessage.BodyEncoding = encoding;
_mailMessage.IsBodyHtml = true;
_mailMessage.Priority = MailPriority.Normal;
if(ccs!=null)
foreach (string cc in ccs)
{
if (!string.IsNullOrEmpty(cc))
{ _mailMessage.CC.Add(cc); }
}
if(bccs!=null)
foreach (string bcc in bccs)
{
if (!string.IsNullOrEmpty(bcc))
{
_mailMessage.CC.Add(bcc);
}
}
try
{
var sendThread = new Thread(SendMailCore);
sendThread.Start(_mailMessage);
_smtpClient.Send(_mailMessage);
message = null;
return true;
}
catch (Exception ex)
{
message = ex.Message;
return false;
}
}
private static void SendMailCore(object message)
{
//邮件配置 Host,账户和密码
string mailHost = ConfigurationManager.AppSettings["MailHost"].Trim().ToString();
string mailAccount = ConfigurationManager.AppSettings["MailAccount"].Trim().ToString();
string mailPassword = ConfigurationManager.AppSettings["MailPassword"].Trim().ToString();
MailMessage msg = message as MailMessage; SmtpClient smtpClient = new SmtpClient
{
Host = mailHost, Port =587, EnableSsl = true,
Credentials = new System.Net.NetworkCredential { UserName = mailAccount, Password = mailPassword }
};
smtpClient.Send(msg);
}
public static bool SendEmail(string mailTitle,string toEmail, string content, out string message,IList<string> ccEmail=null, IList<string> bccEmail=null)
{
string mailFrom= ConfigurationManager.AppSettings["MailAccount"].Trim().ToString();
return SendEmail( mailFrom, toEmail, content, mailTitle, out message, ccEmail, bccEmail);
}
3.方法调用
string _pathTemp = Server.MapPath("");//html 路径
string _mailTitle = "";//邮件文件头
string strContent = EmailCode.GetMailTemp(_pathTemp, GuRuAcount, GuRuPassword);
MyEmailCode.SendEmail(_mailTitle, email, strContent, out message);
实战篇之实现 OutLook 中以 EDM 形式发送通知邮件的更多相关文章
- 在Delphi中使用indy SMTP发送gmail邮件[转]
在Delphi中使用indy SMTP发送gmail邮件[转] 2012-01-01 22:44:30| 分类: Delphi | 标签: |举报 |字号大中小 订阅 在Delphi中发送 ...
- Outlook中在Exchange服务器无法保存邮件副本
最近帮同事设置Outlook2007,结果她直接登录公司网页Exchange,发现存在Exchange上的邮件副本全没了,原以为是Outlook邮箱账号设置里”保存服务器项副本“没打勾,后来才发现账号 ...
- 黑客攻防技术宝典web实战篇:查找源代码中的漏洞习题
猫宁!!! 参考链接:http://www.ituring.com.cn/book/885 随书答案. 1. 列出 3 种可在源代码中找到明确签名的常见漏洞. (a) 跨站点脚本(b) SQL 注入( ...
- [linux] shell脚本编程-统计日志文件中的设备号发通知邮件
1.日志文件列表 比如:/data1/logs/2019/08/15/ 10.1.1.1.log.gz 10.1.1.2.log.gz 2.统计日志中的某关键字shell脚本 zcat *.gz|gr ...
- 如何在Visual Studio 2017中使用C# 7+语法 构建NetCore应用框架之实战篇(二):BitAdminCore框架定位及架构 构建NetCore应用框架之实战篇系列 构建NetCore应用框架之实战篇(一):什么是框架,如何设计一个框架 NetCore入门篇:(十二)在IIS中部署Net Core程序
如何在Visual Studio 2017中使用C# 7+语法 前言 之前不知看过哪位前辈的博文有点印象C# 7控制台开始支持执行异步方法,然后闲来无事,搞着,搞着没搞出来,然后就写了这篇博文,不 ...
- Web安全测试中常见逻辑漏洞解析(实战篇)
Web安全测试中常见逻辑漏洞解析(实战篇) 简要: 越权漏洞是比较常见的漏洞类型,越权漏洞可以理解为,一个正常的用户A通常只能够对自己的一些信息进行增删改查,但是由于程序员的一时疏忽,对信息进行增删改 ...
- 二、Redis基本操作——String(实战篇)
小喵万万没想到,上一篇博客,居然已经被阅读600次了!!!让小喵感觉压力颇大.万一有写错的地方,岂不是会误导很多筒子们.所以,恳请大家,如果看到小喵的博客有什么不对的地方,请尽快指正!谢谢! 小喵的唠 ...
- AngularJS in Action读书笔记6(实战篇)——bug hunting
这一系列文章感觉写的不好,思维跨度很大,原本是由于与<Angularjs in action>有种相见恨晚而激发要写点读后感之类的文章,但是在翻译或是阐述的时候还是会心有余而力不足,零零总 ...
- ROS2.9.27架设网吧软路由实战篇之端口映射与回流
转载:http://blog.csdn.net/zm2714/article/details/7924280 上一篇:ROS2.9.27架设网吧软路由实战篇之连通网络,主要讲述了网吧架设软路由ROS2 ...
随机推荐
- response对象设置输出缓冲大小
response对象设置输出缓冲大小 制作人:全心全意 通常情况下,服务器要输出到客户端的内容不会直接写到客户端,而是先写到一个输出缓冲区,在计算机术语中,缓冲区被定义为暂时放置输入或输出资料的内存. ...
- The Falling Leaves(建树方法)
uva 699 紫书P159 Each year, fall in the North Central region is accompanied by the brilliant colors of ...
- [bzoj1966][Ahoi2005][VIRUS 病毒检测] (字符串dp)
Description 科学家们在Samuel星球上的探险仍在继续.非常幸运的,在Samuel星球的南极附近,探险机器人发现了一个巨大的冰湖!机器人在这个冰湖中搜集到了许多RNA片段运回了实验基地.科 ...
- 3.6.5 空串与Null串
空串""是长度为0的字符串.可以调用以下代码检查一个字符串是否为空: String s = "greeting"; ...
- hadoop full cluster 改为伪分布
https://hadoop.apache.org/docs/r2.7.6/hadoop-project-dist/hadoop-common/SingleCluster.html#Pseudo-Di ...
- New Barns
New Barns 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Farmer John notices that his cows tend to get into argument ...
- 算(tyvjP4700)
背景 zhx和他的妹子出去玩. 描述
- Self Centos + Windows server 2016
Set up by Derek: 2019-1-25 登陆个人物理机: license 60天Free , 如果过期,就在 VMware ESXI 6.5.0的黑屏界面去reset. https:/ ...
- my first emacs custom key binding
(defun comment-this-level () (interactive) (move-beginning-of-line 1) (set-mark-command nil) (fo ...
- POJ——T3417 Network
http://poj.org/problem?id=3417 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5294 A ...