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 形式发送通知邮件的更多相关文章

  1. 在Delphi中使用indy SMTP发送gmail邮件[转]

    在Delphi中使用indy SMTP发送gmail邮件[转] 2012-01-01 22:44:30|  分类: Delphi |  标签: |举报 |字号大中小 订阅     在Delphi中发送 ...

  2. Outlook中在Exchange服务器无法保存邮件副本

    最近帮同事设置Outlook2007,结果她直接登录公司网页Exchange,发现存在Exchange上的邮件副本全没了,原以为是Outlook邮箱账号设置里”保存服务器项副本“没打勾,后来才发现账号 ...

  3. 黑客攻防技术宝典web实战篇:查找源代码中的漏洞习题

    猫宁!!! 参考链接:http://www.ituring.com.cn/book/885 随书答案. 1. 列出 3 种可在源代码中找到明确签名的常见漏洞. (a) 跨站点脚本(b) SQL 注入( ...

  4. [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 ...

  5. 如何在Visual Studio 2017中使用C# 7+语法 构建NetCore应用框架之实战篇(二):BitAdminCore框架定位及架构 构建NetCore应用框架之实战篇系列 构建NetCore应用框架之实战篇(一):什么是框架,如何设计一个框架 NetCore入门篇:(十二)在IIS中部署Net Core程序

    如何在Visual Studio 2017中使用C# 7+语法   前言 之前不知看过哪位前辈的博文有点印象C# 7控制台开始支持执行异步方法,然后闲来无事,搞着,搞着没搞出来,然后就写了这篇博文,不 ...

  6. Web安全测试中常见逻辑漏洞解析(实战篇)

    Web安全测试中常见逻辑漏洞解析(实战篇) 简要: 越权漏洞是比较常见的漏洞类型,越权漏洞可以理解为,一个正常的用户A通常只能够对自己的一些信息进行增删改查,但是由于程序员的一时疏忽,对信息进行增删改 ...

  7. 二、Redis基本操作——String(实战篇)

    小喵万万没想到,上一篇博客,居然已经被阅读600次了!!!让小喵感觉压力颇大.万一有写错的地方,岂不是会误导很多筒子们.所以,恳请大家,如果看到小喵的博客有什么不对的地方,请尽快指正!谢谢! 小喵的唠 ...

  8. AngularJS in Action读书笔记6(实战篇)——bug hunting

    这一系列文章感觉写的不好,思维跨度很大,原本是由于与<Angularjs in action>有种相见恨晚而激发要写点读后感之类的文章,但是在翻译或是阐述的时候还是会心有余而力不足,零零总 ...

  9. ROS2.9.27架设网吧软路由实战篇之端口映射与回流

    转载:http://blog.csdn.net/zm2714/article/details/7924280 上一篇:ROS2.9.27架设网吧软路由实战篇之连通网络,主要讲述了网吧架设软路由ROS2 ...

随机推荐

  1. LINUX-磁盘空间

    df -h 显示已经挂载的分区列表 ls -lSr |more 以尺寸大小排列文件和目录 du -sh dir1 估算目录 'dir1' 已经使用的磁盘空间' du -sk * | sort -rn ...

  2. * average vector from multiple files--Matlab

    n=359;a=[];b=[];c=[];% for loopfor i=1:n      filename=sprintf('output_%d.dat',i);    fileinfo = imp ...

  3. 【Codeforces 582A】GCD Table

    [链接] 我是链接,点我呀:) [题意] 给你一个数组A[]经过a[i][j] = gcd(A[i],A[j])的规则生成的二维数组 让你求出原数组A [题解] 我们假设原数组是A 然后让A数组满足A ...

  4. fzu2143 Board Game

    Board Game Accept: 54    Submit: 151Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Descri ...

  5. ACE in Action

    ACE in Action https://cdn.xgqfrms.xyz/web-ide/index.html TinyMCE https://panjiachen.github.io/vue-el ...

  6. POJ2528 Uva10587 Mayor's posters

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

  7. [luoguP2858] [USACO06FEB]奶牛零食Treats for the Cows(DP)

    传送门 f[i][j][k] 表示 左右两段取到 i .... j 时,取 k 次的最优解 可以优化 k 其实等于 n - j + i 则 f[i][j] = max(f[i + 1][j] + a[ ...

  8. 【BZOJ3238】差异(后缀数组,单调栈)

    题意: 思路:显然len(t[i])+len(t[j])这部分的和是一定的 那么问题就在于如何快速求出两两之间lcp之和 考虑将它们排名后用SA可以很方便的求出lcp,且对答案没有影响,因为形式都是数 ...

  9. LSN

    http://www.cnblogs.com/lyhabc/archive/2013/07/16/3194220.html

  10. 小米2S 小米手机如何手动升级到开发版

    1 从官网下载系统的更新包,比如对于小米2S,从下面的网址下载. http://www.miui.com/download-2.html     2 下载完成之后,放到手机的任意文件夹下,比如下面的S ...