会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
Socansoft 官网:socansoft.com
廖勇军
发送邮件事例
protected
void
btnSend_Click(
object
sender, EventArgs e)
{
string
rcvAddr
=
txtMailAddr.Text.Trim();
if
(rcvAddr.Length
>
0
)
{
//
邮件信息
MailMessage mail
=
new
MailMessage();
mail.From
=
new
MailAddress(
"
Socansoft<liaoyongjun@gmail.com>
"
);
mail.Subject
=
"
测试邮件
"
;
mail.IsBodyHtml
=
true
;
mail.BodyEncoding
=
System.Text.Encoding.Default;
mail.Body
=
"
你好,这是自动发送的,请勿回复!
"
;
string
[] rcvs
=
rcvAddr.Split(
new
char
[]
{
'
,
'
}
);
foreach
(
string
rcv
in
rcvs)
{
mail.To.Add(
new
MailAddress(rcv));
}
//
SMTP服务器
SmtpClient client
=
new
SmtpClient();
client.Host
=
"
smtp.gmail.com
"
;
client.EnableSsl
=
true
;
//
需要验证,用户名和密码要正确
client.Credentials
=
new
System.Net.NetworkCredential(
"
liaoyongjun@gmail.com
"
,
"
123456
"
);
//
接收邮件的邮箱
try
{
client.Send(mail);
Response.Write(
"
邮件成功发送到
"
+
mail.To.ToString()
+
"
<br>
"
);
}
catch
(Exception ex)
{
Response.Write(ex.Message
+
"
<br>
"
);
}
}
else
{
Response.Write(
"
联系邮箱不能为空
"
);
}
}
posted on
2007-09-11 17:38
廖勇军
阅读(
457
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理
公告