zoukankan
html css js c++ java
ASP.NET邮件外发
string
myemail
=
TextBox1.Text;
string
euser
=
TextBox2.Text;
string
pass
=
TextBox3.Text;
string
emailTo
=
TextBox4.Text;
string
title
=
TextBox5.Text;
string
semail
=
RadioButtonList1.SelectedValue.ToString();
string
smtp
=
TextBox6.Text;
if
(semail
==
"
1
"
)
{
MailMessage mailMsg
=
new
MailMessage();
//
设置正文格式
mailMsg.BodyFormat
=
MailFormat.Html;
//
设置收件人的邮件地址
mailMsg.To
=
emailTo;
//
设置发送者的邮件地址
mailMsg.From
=
myemail;
//
设置邮件主题
mailMsg.Subject
=
title;
//
设置邮件内容
mailMsg.Body
=
"
test
"
;
//
设置支持服务器验证
mailMsg.Fields.Add(
"
http://schemas.microsoft.com/cdo/configuration/smtpauthenticate
"
,
"
1
"
);
//
设置用户名
mailMsg.Fields.Add(
"
http://schemas.microsoft.com/cdo/configuration/sendusername
"
, euser);
//
设置用户密码
mailMsg.Fields.Add(
"
http://schemas.microsoft.com/cdo/configuration/sendpassword
"
, pass);
try
{
//
设置发送邮件服务器
SmtpMail.SmtpServer
=
smtp;
//
发送邮件
SmtpMail.Send(mailMsg);
Response.Write(
"
<script>alert('System.Web.Mail方法发信成功,请注意查收!');</script>
"
);
}
catch
(Exception err)
{
Response.Write(
"
System.Web.Mail方法发信失败!
"
+
err.Message.ToString());
}
}
else
{
jmail.Message Jmail
=
new
jmail.Message();
DateTime t
=
DateTime.Now;
String Subject
=
title;
String body
=
"
test
"
;
String FromEmail
=
myemail;
String ToEmail
=
emailTo;
//
Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
Jmail.Silent
=
true
;
//
Jmail创建的日志,前提loging属性设置为true
Jmail.Logging
=
true
;
//
字符集,缺省为"US-ASCII"
Jmail.Charset
=
"
GB2312
"
;
//
信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
Jmail.ContentType
=
"
text/html
"
;
//
添加收件人
Jmail.AddRecipient(ToEmail,
""
,
""
);
Jmail.From
=
FromEmail;
//
发件人邮件用户名
Jmail.MailServerUserName
=
euser;
//
发件人邮件密码
Jmail.MailServerPassWord
=
pass;
//
设置邮件标题
Jmail.Subject
=
Subject;
//
邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
//
Jmail.AddAttachment("c:\\test.jpg", true, null);
//
邮件内容
Jmail.Body
=
"
test
"
;
//
Jmail发送的方法
Jmail.Send(smtp,
false
);
Jmail.Close();
if
(Jmail.Send(smtp,
false
)
==
true
)
{
Response.Write(
"
<script>alert('Jmail方法发信成功,请注意查收!');</script>
"
);
}
else
{
Response.Write(
"
<script>alert('Jmail方法发信失败!');</script>
"
);
}
}
查看全文
相关阅读:
记录一次SpringCloud Alibaba整合Springboot出现的'com.netflix.client.config.IClientConfig' that could not be found
ysoserial-URLDNS链分析
DIVA闯关-APP测试
前端页面直接转换为PDF文件流
中位数最大问题
【vim】Linux添加环境变量等
FFmpeg使用笔记
【memo】及时留坑
【album】深度学习 / 机器学习 / 人工智能
【Linux】软件安装使用【aubio / FFmpeg】
原文地址:https://www.cnblogs.com/wdx2008/p/994275.html
最新文章
laravel 自定义 ApiException
cURL error 60: SSL certificate problem: unable to get local issuer certificate 报错解决方案(laravel 使用GGuzzleHttp报错解决)
使用Fiddler对手机小程序进行抓包
laravel重新封装paginate翻页
Spring配置
将实体类序列化
mybatis-缓存
mybatis-动态SQL,SQL标签
mybatis一对多操作数据库
mybatis多对一数据库查询
热门文章
lombok的使用
mybatis通过注解完成数据库操作(不适用xml配置)
SpringBoot的几种日志级别
axios的几种参数传递方式
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.14.1 postinst
volatile作用与底层原理
JVM内存模型
Mybatis中SqlSession、SqlSessionTemplate、SqlSessionFactory、SqlSessionFactoryBean之间的关系
记两次线上出现的索引失效的问题
Ribbon配置大全
Copyright © 2011-2022 走看看