发送邮件 html格式
下面黄色代码为实现发送邮件
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格式的更多相关文章
- Python使用SMTP发送邮件[HTML格式、送带附件]
SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. python的smtplib提供了一 ...
- asp.net发送邮件带格式(本demo发送验证码)
public ActionResult Mail(string email, string userName) { try { MailSender mail = new MailSender(); ...
- sql发送邮件- html 格式
ALTER PROCEDURE dbo.sx_pro_AutoEmailContent AS Begin declare @Rqty int declare @n int declare @m_rec ...
- SQL SERVER 2008自动发送邮件(完整版)
这两天都在搞这个东西,从开始的一点不懂,到现在自己可以独立的完成这个功能!在这个过程中,CSDN的好多牛人都给了我很大的帮助,在此表示十二分的感谢!写这篇文章,一是为了巩固一下,二嘛我也很希望我写的这 ...
- Log4j发送邮件
源码地址:https://github.com/mistbor/Log4jSendMail 引入activation.jar log4j.jar mail.j ...
- linux下使用自带mail发送邮件
linux下使用自带mail发送邮件 mailx工具说明: linux可以通过安装mailx工具,mailx是一个小型的邮件发送程序,一般可以通过该程序在linux系统上,进行监控linux系统状态并 ...
- 使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样
使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样openid生成是根据应用的appid和QQ号的一些信息加密生成,对于一个appid和QQ号来说,openid是唯一的 ...
- Jenkins学习四:Jenkins 邮件配置
本文主要对Windows环境 jenkins 的邮件通知进行介绍 jenkins 内置的邮件功能 使用email-ext插件扩展的邮件功能 邮件通知功能主要包含两个部分:全局配置和项目配置. 一. 先 ...
- Jenkins进阶系列之——01使用email-ext替换Jenkins的默认邮件通知
1 简述 众所周知,Jenkins默认提供了一个邮件通知,能在构建失败.构建不稳定等状态后发送邮件.但是它本身有很多局限性,比如它的邮件通知无法提供详细的邮件内容.无法定义发送邮件的格式.无法定义灵活 ...
随机推荐
- groovy运算符
import java.util.regex.Matcher /** * Created by Jxy on 2018/12/20 10:29 * groovy运算符 */ /*class opera ...
- 高并发第二弹:并发概念及内存模型(JMM)
高并发第二弹:并发概念及内存模型(JMM) 感谢 : 深入Java内存模型 http://www.importnew.com/10589.html, cpu缓存一致性 https://www.cnbl ...
- java语言的各种输入情况(ACM常用)
1.只输入一组数据: Scanner s=new Scanner(System.in); int a=s.nextInt(); int b=s.nextInt(); 2.输入有多组数据,没有说明输入几 ...
- PostgreSQL Metadata
http://www.devart.com/dotconnect/postgresql/docs/MetaData.html In this overload first parameter is ...
- BZOJ2187:fraction
Sol 分情况讨论 \(\lfloor\frac{a}{b}\rfloor+1\le \lceil\frac{c}{d}\rceil-1\) 直接取 \(q=1,p=\lfloor\frac{a}{b ...
- Swiper测试
在页面body中插入 <div class="swiper-container temp"> <div class="swiper-wrapper&qu ...
- ant-design里为了清空Modal中的值, modal 中值有缓存 ....
处理列表中的编辑功能,发现有点爽,看的都是上次编辑后内容, 搜文档 也没说具体怎么清空旧的状态 网上搜了下,说给 moal 设置一个不同的key 试了,用这方式可以解决问题, 只要这个key是全新的 ...
- Python爬虫教程-10-UserAgent和常见浏览器UA值
Python爬虫教程-10-UserAgent和常见浏览器UA值 有时候使用爬虫会被网站封了IP,所以需要去模拟浏览器,隐藏用户身份, UserAgent 包含浏览器信息,用户身份,设备系统信息 Us ...
- 算法之求质数(Java语言)
质数(Prime number) 又称素数,指在的自然数中,除了1和该数自身外,无法被其他自然数整除的数(也可定义为只有1与该数本身两个因数的数). 算法原理 验证一个数字 n 是否为素数的一种简单但 ...
- SSH 无法启动的原因分析及解决方法
简介 Secure Shell(缩写为 SSH),由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为一项创建在应用层和传输层基础上的安全协议,为计算机上的 S ...