发送邮件 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默认提供了一个邮件通知,能在构建失败.构建不稳定等状态后发送邮件.但是它本身有很多局限性,比如它的邮件通知无法提供详细的邮件内容.无法定义发送邮件的格式.无法定义灵活 ...
随机推荐
- 利用QVOD架设流媒体服务器/电影服务器/vod服务器
电影服务器一点也不稀罕,是的我们见的太多了,但是大家有没有想过自己也能架一个这样的服务器? 当然现在架一个电影服务器不切实际,去年吵的闹哄哄的“视听许可证”想必大家有所耳闻,再加上电影对服务器的要求一 ...
- UOJ46. 【清华集训2014】玄学
传送门 Sol 考虑对于操作时间建立线段树,二进制分组 那么现在主要的问题就是怎么合并信息 你发现一个性质,就是每个修改只会在整个区间内增加两个端点 那么我们二进制分组可以得到每个区间内最多只有区间长 ...
- Child extends Parent,可以得到什么?
如果有Child extends Parent 1.子类可以调用父类无参的构造函数,子类的有参构造函数和是否调用父类的有参数的构造函数无必然联系 2.接口继承的时候,只能继承接口不能继承类,因为如果类 ...
- bootstrap学习笔记细化(标题)
bootstrap中的排版: 标题(h1~h6/.h1~.h6) h1:36px;h2:30px;h3:24px;h4:18px;h5:14px;h6:12px; 副标题(small) 小练习(标题大 ...
- Ubuntu,忘记了root密码,怎么重置?
进入单用户模式: 1.开机到grub时,用上下键移到第二行的恢复模式,按e(注意不是回车) 即Ubuntu,With Linux 3.2.0-23-generic(recovery mode) 2.把 ...
- BigInteger方法总结
BigInteger 可以用来解决数据的溢出问题. 下面我总结几种关于BigInteger的常用用法: 1.probablePrime和nextprobablePrime.(判断质数,并返回) Big ...
- vs的一个奇葩错误 : 未能找到任何适合于指定的区域性或非特定区域性的资源...
摘要: VS2005下进行开发的时候遇到的问头:未能找到任何适合于指定的区域性或非特定区域性的资源.请确保在编译时已将“xxx.Form1.resources”正确嵌入或链接到程序集“xxx”,或者确 ...
- eclipse 乱码问题总结
Eclipse 的控制台必须用GBK编码.所以条件1和条件4必须同时满足否则运行的还是乱码.才能保证不是乱码. 条件1,Window | Preferences | Workspace | T ...
- oracle decode函数和 sign函数
流程控制函数 DECODE decode()函数简介: 主要作用: 将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明): 使用方法: Select decode(columnname,值1, ...
- 贪心算法和动态规划[zz]
http://www.cnblogs.com/asuran/archive/2010/01/26/1656399.html 贪心算法 1.贪心选择性质 所谓贪心选择性质是指所求问题的整体最优解可以通过 ...