wdx2008
博客园
首页
新随笔
联系
订阅
管理
随笔 - 28 文章 - 14 评论 - 8 trackbacks - 3
<
2007年12月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
昵称:
wdx2008
园龄:
4年9个月
粉丝:
0
关注:
0
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
随笔分类
web.config(1)
常用代码块(1)
随笔档案
2008年3月 (1)
2008年2月 (3)
2008年1月 (2)
2007年12月 (4)
2007年7月 (3)
2007年6月 (15)
最新评论
阅读排行榜
评论排行榜
推荐排行榜
2007年12月13日
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>
"
);
}
}
posted @ 2007-12-13 23:27 wdx2008 阅读(157) 评论(0)
编辑