下面黄色代码为实现发送邮件

FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/productConsultAnwser.html"), FileMode.OpenOrCreate, FileAccess.Read);
                                StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                                string strTemp = sr.ReadToEnd();
                                sr.Close();
                                fs.Close();
                                //if (queryTemp.spec_name1 == "" && queryTemp.spec_name2 == "")
                                //{
                                //    product_name = queryTemp.brand_name + queryTemp.product_name;
                                //}
                                //else
                                //{
                                //    product_name = queryTemp.brand_name + queryTemp.product_name + "(" + queryTemp.spec_name1 + "  " + queryTemp.spec_name2 + ")";
                                //}
                                product_name = queryTemp.product_name;
                                strTemp = strTemp.Replace("{{$username$}}", userName);
                                strTemp = strTemp.Replace("{{$productName$}}", product_name);
                                strTemp = strTemp.Replace("{{$consultInfo$}}", consultInfo);
                                strTemp = strTemp.Replace("{{$consultAnwser$}}", answerInfo);
                                strTemp = strTemp.Replace("{{$productUrl$}}", productUrl);
                                sendmail(EmailFrom, FromName, userEmail, userName, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord);

public bool sendmail(string sfrom, string sfromer, string sto, string stoer, string sSubject, string sBody, string sfile, string sSMTPHost, int sSMTPPort, string sSMTPuser, string sSMTPpass)
        {
            ////设置from和to地址
            MailAddress from = new MailAddress(sfrom, sfromer);
            MailAddress to = new MailAddress(sto, stoer);

////创建一个MailMessage对象
            MailMessage oMail = new MailMessage(from, to);
            //// 添加附件
            if (sfile != "")
            {
                oMail.Attachments.Add(new Attachment(sfile));
            }
            ////邮件标题
            oMail.Subject = sSubject;
            ////邮件内容
            //oMail.Body = sBody;
            AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(sBody, null, "text/html");
            oMail.AlternateViews.Add(htmlBody);
            ////邮件格式
            oMail.IsBodyHtml = true;
            ////邮件采用的编码
            oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
            ////设置邮件的优先级为高
            oMail.Priority = MailPriority.Normal;
            ////发送邮件
            SmtpClient client = new SmtpClient();
            ////client.UseDefaultCredentials = false;
            client.Host = sSMTPHost;
            client.Port = sSMTPPort;
            client.Credentials = new NetworkCredential(sSMTPuser, sSMTPpass);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                client.Send(oMail);
                return true;
            }
            catch (Exception ex)
            {
             
            }
            finally
            {
                ////释放资源
                oMail.Dispose();
            }

}

发送邮件 html格式的更多相关文章

  1. Python使用SMTP发送邮件[HTML格式、送带附件]

    SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. python的smtplib提供了一 ...

  2. asp.net发送邮件带格式(本demo发送验证码)

    public ActionResult Mail(string email, string userName) { try { MailSender mail = new MailSender(); ...

  3. sql发送邮件- html 格式

    ALTER PROCEDURE dbo.sx_pro_AutoEmailContent AS Begin declare @Rqty int declare @n int declare @m_rec ...

  4. SQL SERVER 2008自动发送邮件(完整版)

    这两天都在搞这个东西,从开始的一点不懂,到现在自己可以独立的完成这个功能!在这个过程中,CSDN的好多牛人都给了我很大的帮助,在此表示十二分的感谢!写这篇文章,一是为了巩固一下,二嘛我也很希望我写的这 ...

  5. Log4j发送邮件

    源码地址:https://github.com/mistbor/Log4jSendMail 引入activation.jar           log4j.jar            mail.j ...

  6. linux下使用自带mail发送邮件

    linux下使用自带mail发送邮件 mailx工具说明: linux可以通过安装mailx工具,mailx是一个小型的邮件发送程序,一般可以通过该程序在linux系统上,进行监控linux系统状态并 ...

  7. 使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样

    使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样openid生成是根据应用的appid和QQ号的一些信息加密生成,对于一个appid和QQ号来说,openid是唯一的 ...

  8. Jenkins学习四:Jenkins 邮件配置

    本文主要对Windows环境 jenkins 的邮件通知进行介绍 jenkins 内置的邮件功能 使用email-ext插件扩展的邮件功能 邮件通知功能主要包含两个部分:全局配置和项目配置. 一. 先 ...

  9. Jenkins进阶系列之——01使用email-ext替换Jenkins的默认邮件通知

    1 简述 众所周知,Jenkins默认提供了一个邮件通知,能在构建失败.构建不稳定等状态后发送邮件.但是它本身有很多局限性,比如它的邮件通知无法提供详细的邮件内容.无法定义发送邮件的格式.无法定义灵活 ...

随机推荐

  1. veloctiy入门

    什么是velocity? velocity是一个基于Java的模板引擎.你可以使用它来预定义模板,并且对模板进行数据渲染,从而动态生成相应的文本.它如同JSP一样经常被使用在MVC分层架构当中,充当V ...

  2. hdu 1251 统计难题 字典树第一题。

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  3. 循环遍历正则验证input框内容合法性

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. DOM基础代码练习(一)

    上一篇介绍了一下DOM的一些基础的知识,这里我整理了一些有关上一篇知识点的一些封装函数. 1.遍历元素节点 function retChild(node) { var child = node.chi ...

  5. mysql中LOCATE和CASE WHEN...THEN...ELSE...END结合用法

    之前项目中需要写一个sql,就是查出某个调研详情中,选A答案,B答案,C答案...F答案的人各有多少人,这个sql也是费了很大的力气才写出来,故记下来,方便以后使用. 其中tbl_research_i ...

  6. 状态开关(ToggleButton)

    状态开关(ToggleButton): 常用属性:isChecked(是否被选中,如true) 监听:1.监听方法:setOnCheckedChangeListener 2.监听器:CompoundB ...

  7. 浅谈搜索引擎SEO(HTML/CSS)

    SEO:搜索引擎优化(免费): SEM:搜索引擎营销(付费). 它们两者的区别是: 1.SEM高投入,SEO低投入: 2.SEM短.效益块,SEO长期投入.增长慢: 3.新广告法颁布之后SEM广告位减 ...

  8. 1 win10双系统安装ubuntu16.04和18.04(问题详细记录)

    我从来不想在琐事上花功夫.就拿装系统来说,我感觉拿过来一个完全陌生的项目源码,看起来,都比装系统爽.我属于典型的逻辑思考男.喜欢畅游程序的海洋. 一直windows跑深度学习和tensorflow,有 ...

  9. C语言指针数组(每个元素都是指针)

    转载:http://c.biancheng.net/cpp/html/3246.html 注意:数组指针的区别 如果一个数组中的所有元素保存的都是指针,那么我们就称它为指针数组.指针数组的定义形式一般 ...

  10. apple 下安装mysql 以及 碰到的问题

    直接说过程: 1.从mysql 官网下载 mysql 5.7最新版:有 两种 一种是 dmg 的傻瓜包,一种是tar.gz的压缩包.我下载的是tar.gz的压缩包. 2.下载成功后,先试用命令sudo ...