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

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. [linux] shell脚本编程-xunsearch安装脚本学习

    安装脚本setup.sh #!/bin/sh # FULL fast install/upgrade script # See help message via `--help' # $Id$ # s ...

  2. mysql数据库重点(基础优化)

    ### Mysql性能优化 尽量不要写select * ,如果需要全表数据,使用select 加所有字段列名称查询代替* 尽量减少字段列的数学计算,如:where num * 2 >= 30,可 ...

  3. 【SSH网上商城项目实战28】使用Ajax技术局部更新商品数量和总价

         转自: https://blog.csdn.net/eson_15/article/details/51487323 昨天把项目部署了一下,玩了玩,今天完善了一下购物车中修改商品数量就能局部 ...

  4. 工厂模式的认识(GOF23)

    ---恢复内容开始--- 对于所有的设计模式来说,其本质是哪里变化封装哪里.寻找变化点,没有万能的模式,只有适合情况的应用 工厂模式从简单工厂开始演化 1.简单工厂的主要作用在于从源头开始封装实例化, ...

  5. Child extends Parent,可以得到什么?

    如果有Child extends Parent 1.子类可以调用父类无参的构造函数,子类的有参构造函数和是否调用父类的有参数的构造函数无必然联系 2.接口继承的时候,只能继承接口不能继承类,因为如果类 ...

  6. Struts2详讲

    一 概述 1.什么是Struts2? Struts2是一个在WebWork框架基础上发展起来开源MVC框架. 2.StrutsPrepareAndExecuteFilter StrutsPrepare ...

  7. along.js

    平时写代码用到的方法,就给封装了一下.需要的拿走不谢... 1.数组去重 并判断一个元素出现的次数 handle(str){ let arr=str.split('') var newarr=[]; ...

  8. vue项目创建

    使用命令行工具npm新创建一个vue项目   使用vue开发项目的前期工作可以参考前面写的:  Vue环境搭建及node安装过程整理 Vue.js 提供一个官方命令行工具,可用于快速搭建大型单页应用. ...

  9. 【MFC】CDialogBar中按钮不可用

    现象展示: 具体原因: A button in a CDialogBar object is disabled automatically if the command routing does no ...

  10. [C++]多线程: 教你写第一个线程

    原文:http://blog.csdn.net/cn_wk/article/details/62236057 hello thread! 声明线程A的端口号 #include <pthread. ...