实战篇之实现 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 ...
随机推荐
- 60.通过应用层join实现用户与博客的关联
在构造数据模型的时候,将有关联关系的数据分割为不同的实体,类似于关系型数据库中的模型. 案例背景:博客网站,一个网站可能有多个用户,一个用户会发多篇博客,此时最好的方式是建立users和blogs两个 ...
- circumferential averge streamwise velocity using Tecplot and Matlab
Input: results from solver output: circumferential averge physical quantities( such as streamwise ve ...
- 【C++】实现记录软件计时时间
利用getTickCount()和getTickFrequency()函数实现计时 double time0 = static_cast<double>(getTickCount()); ...
- 【02】Node.js 安装配置(OK)
[02] Node.js 安装配置 本章节我们将向大家介绍在window和Linux上安装Node.js的方法. Node.js安装包及源码下载地址为:http://www.nodejs.org/do ...
- 关于字符串不为空 错误:s!=null
错误:s!=null 正确:StringUtils.isNotBlank(s); public static boolean isBlank(CharSequence cs) { int strLen ...
- Android layer-list:联合shape(2)
Android layer-list:联合shape(2) 附录文章3简单说明了Android layer-list的用法,现在把Android layer-list联合shape做出一些特殊的 ...
- 将Jquery EasyUI中DataGird的数据导入Excel中
1.第一步获取前台DataGrid中的数据 var rows = $('#tb).datagrid("getRows"); if (rows.length = ...
- Ubuntu 16.04安装Synaptic Package Manager图形化APT管理工具
安装: sudo apt-get install synaptic 启动:
- Windows 10+Ubuntu 16.04在MBR分区上安装双系统(转)
以下内容转自这篇博客: http://www.cnblogs.com/Duane/p/5424218.html http://www.cnblogs.com/Duane/p/6776302.html( ...
- HDFS v1.0学习笔记
hdfs是一个用于存储大文件的分布式文件系统,是apache下的一个开源项目,使用java实现.它的设计目标是可以运行在廉价的设备上,运行在大多数的系统平台上,高可用,高容错,易于扩展. 适合场景 存 ...