实战篇之实现 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 ...
随机推荐
- jsonview插件的常见使用方法整理
Jsonview是目前最热门的一款开发者工具插件,确切的来说jQuery JSONView是一款非常实用的格式化和语法高亮JSON格式数据查看器jQuery插件.它是查看json数据的神器. 下载地址 ...
- 洛谷 2922 BZOJ 1590 [USACO08DEC]秘密消息Secret Message
[题意概述] 给出n个01串组成的字典和m个询问,每次询问某个01串和多少个字典中的串有相同的前缀.(前缀长度是两串中较小的部分) [题解] 直接上Trie树即可.树上每个节点记录两个信息:这个节点有 ...
- [模拟赛FJOI Easy Round #2][T1 sign] (模拟+求字符串重复字串)
[题目描述] 小Z在无意中发现了一个神奇的OJ,这个OJ有一个神奇的功能:每日签到,并且会通过某种玄学的算法计算出今日的运势.在多次试验之后,小Z发现自己的运势按照一定的周期循环,现在他找到了你,请通 ...
- MySQL 乐观锁和悲观锁
前言 1)在数据库的锁机制中介绍过,数据库管理系统(DBMS)中的并发控制的任务是确保在多个事务同时存取数据库中同一数据时不破坏事务的隔离性和一致性以及数据库的一致性. 2)加锁是为了解决更新丢失问题 ...
- java 反射运用
一,获取私有的属性,方法,构造器(俗名:暴力反射) 现有一个类,属性,方法,构造器均为私有的,如何创建实例对象,更该属性值,调用方法? public class Student { private S ...
- 第2章 取得大家的支持 录播感悟(意外的Sprint)
关于<取得大家的支持>这个故事我看了三遍,做了计划,做了时间轴,因为之前有过第1章<知易行难>的沟通和磨合后,相信会顺利很多吧!可是却是意外不断的发生: 1.本人车钥匙掉停车场 ...
- RMI分布式议程服务学习
转自:http://6221123.blog.51cto.com/6211123/1112619 这里讲述的是基于JDK1.5的RMI程序搭建,更简单的说是一个 HelloWorld RMI. 1. ...
- PatentTips - Method for booting a host device from an MMC/SD device
FIELD OF THE INVENTION The present invention relates to a memory device and especially to the interf ...
- [bzoj 1093][ZJOI2007]最大半联通子图(强联通缩点+DP)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1093 分析: 首先肯定是先把强联通全部缩成一个点,然后成了一个DAG 下面要知道一点: ...
- Android: 关于百度地图缩放级别
18 ~ 3 {"50m","100m","200m","500m","1km","2km ...