zoukankan
html css js c++ java
Asp.Net 发送邮件
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Net.Mail;
public
partial
class
Default3 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
/**/
///
<summary>
///
发送邮件
///
</summary>
///
<param name= "strSmtpServer ">
smtp地址
</param>
///
<param name= "UserName ">
用户名
</param>
///
<param name= "Password ">
密码
</param>
///
<param name= "strFrom ">
发信人地址
</param>
///
<param name= "strto ">
收信人地址
</param>
///
<param name= "strSubject ">
邮件标题
</param>
///
<param name= "strBody ">
邮件正文
</param>
public
static
void
SendMail(
string
strSmtpServer,
string
UserName,
string
Password,
string
strFrom,
string
strto,
string
strSubject,
string
strBody,
string
strFileName)
{
//
生成一个 使用SMTP发送邮件的客户端对象
System.Net.Mail.SmtpClient client
=
new
System.Net.Mail.SmtpClient(strSmtpServer);
//
表示以当前登录用户的默认凭据进行身份验证
client.UseDefaultCredentials
=
true
;
//
包含用户名和密码
client.Credentials
=
new
System.Net.NetworkCredential(UserName, Password);
//
指定如何发送电子邮件。
//
Network 电子邮件通过网络发送到 SMTP 服务器。
//
PickupDirectoryFromIis 将电子邮件复制到挑选目录,然后通过本地 Internet 信息服务 (IIS) 传送。
//
SpecifiedPickupDirectory 将电子邮件复制到 SmtpClient.PickupDirectoryLocation 属性指定的目录,然后由外部应用程序传送。
client.DeliveryMethod
=
System.Net.Mail.SmtpDeliveryMethod.Network;
//
建立邮件对象
System.Net.Mail.MailMessage message
=
new
System.Net.Mail.MailMessage(strFrom, strto, strSubject,strBody);
//
定义邮件正文,主题的编码方式
message.BodyEncoding
=
System.Text.Encoding.GetEncoding(
"
gb2312
"
);
message.SubjectEncoding
=
System.Text.Encoding.GetEncoding(
"
gb2312
"
);
//
获取或设置一个值,该值指示电子邮件正文是否为 HTML。
message.IsBodyHtml
=
false
;
//
指定邮件优先级
message.Priority
=
System.Net.Mail.MailPriority.Normal;
//
添加附件
//
System.Web.Mail.MailAttachment mailAttachment=new System.Web.Mail.MailAttachment(@ "f:/baihe.txt ");
if
(strFileName
!=
""
&&
strFileName
!=
null
)
{
Attachment data
=
new
Attachment(strFileName);
message.Attachments.Add(data);
}
//
发件人身份验证,否则163 发不了
client.Credentials
=
new
System.Net.NetworkCredential(strFrom, Password);
//
发送
client.Send(message);
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
SendMail(
"
smtp.163.com
"
,
"
xxxxxx
"
,
"
xxxxxx
"
,
"
xxxxx
"
,
"
xxxxx
"
,
"
1111111
"
,
"
dsfsfsfsdffsd
"
,
""
);
}
}
查看全文
相关阅读:
服务器操作nginx相关操作命令
git使用命令
超出隐藏显示
微信小程序清除默认样式
程序员提升之排查bug的能力
call和apply的基本用法与区别
vuejs 插件开发并发布到npm--(3)vue组件开发并发布
vuejs 插件开发并发布到npm--(2)js插件开发
vuejs 插件开发并发布到npm--(1)为什么要进行插件开发管理
双机热备份和负载均衡的区别
原文地址:https://www.cnblogs.com/ziyan22/p/1244273.html
最新文章
arp
ip协议
分层
软件质量模型的六大特性27个子特性
Confident Learning: Estimating Uncertainty in Dataset Labels
一些前端笔记、好用网站
pytorch好案例 用于借鉴模仿
xxtest
test loss可视化 pytorch
python 中的[:-1]和[::-1]的具体使用
热门文章
CAM(类激活映射),卷积可视化,神经网络可视化,一个库搞定,真的简单的不能再简单
报错Requirement already satisfied:
argparse.ArgumentParser()用法解析
python 自定义模块的导入
git使用心得记录 revert和reset区别
忧郁句子
前端面试题
解决push报错 src refspec vue_develop does not match any.
git拉取代码的时候提示Authentication failed for []
nginx配置、域名、前端代码部署
Copyright © 2011-2022 走看看