会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
天道酬勤
天道酬勤
博客园
首页
新随笔
联系
订阅
管理
Send GMail
今天想着收集一下如何用C#代码来实现发送GMail.
下面是我自己写的测试方法,测试通过。
Send GMail Code
static
void
SendGMail()
{
try
{
//
Article:
http://www.geekzone.co.nz/tonyhughes/599
//
smtp.gmail.com (use authentication)
//
Use Authentication: Yes
//
Use STARTTLS: Yes (some clients call this SSL)
//
Gmail Port: 465 or 587
int
port
=
587
;
string
from
=
"
from@gmail.com
"
;
string
to
=
"
to@sina.com
"
;
string
userid
=
"
from
"
;
string
password
=
"
XXX
"
;
MailMessage msg
=
new
MailMessage(from, to);
msg.Subject
=
"
test mail through Gmail by Bu Hai-Qing
"
;
msg.Body
=
"
Hello World!
"
;
SmtpClient client
=
new
SmtpClient(
"
smtp.gmail.com
"
,
587
);
NetworkCredential crendetial
=
new
NetworkCredential(userid, password);
client.EnableSsl
=
true
;
client.UseDefaultCredentials
=
false
;
client.Credentials
=
crendetial;
client.Send(msg);
}
catch
(System.Exception ex)
{
}
}
posted @
2008-11-16 11:04
卜海清
阅读(
261
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告