downmoon's Blog
邀月的博客周记
登录
注册
全站
当前博客
空间
博客
好友
相册
留言
vs2003 和vs2005下的发送SMTP邮件 (downmoon原创)
收藏
vs2003 和vs2005下的发送SMTP邮件 (downmoon原创)
一、vs2003
引用 System.Web.Mail命名空间
private
void
SenMail2003()
...
{
MailMessage mailObj
=
new
MailMessage();
mailObj.To
=
this
.txtTo.Text;
mailObj.From
=
this
.txtFrom.Text;
mailObj.Subject
=
"
精采笑话
"
;
mailObj.Body
=
"
猪!你已中毒! 哈哈
"
;
mailObj.BodyFormat
=
MailFormat.Html;
mailObj.BodyEncoding
=
MailFormat.Base64;
mailObj.Priority
=
MailPriority.High;
mailObj.Attachments.Add(
new
MailAttachment(
"
c:\swf\000.bmp
"
));
SmtpMail.Send(mailObj);
Response.Write(
"
发送邮件成功!
"
);
}
二、vs2005
引用 System.Net.Mail命名空间,安全性得到了增强
public
static
void
SendWebMailAndAttach(
string
server)
...
{
string
file
=
"
e:\inetpub\wwwroot\Test2005All\TestXML\testXML.xml
"
;
System.Net.Mail.MailMessage message
=
new
System.Net.Mail.MailMessage(
"
Test@126.com
"
,
"
Test@126.com
"
,
"
text message for you.
"
,
"
Test Title
"
);
System.Net.Mail.Attachment data
=
new
System.Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
System.Net.Mime.ContentDisposition disposition
=
data.ContentDisposition;
disposition.CreationDate
=
System.IO.File.GetCreationTime(file);
disposition.ModificationDate
=
System.IO.File.GetLastWriteTime(file);
disposition.ReadDate
=
System.IO.File.GetLastAccessTime(file);
message.Attachments.Add(data);
System.Net.Mail.SmtpClient client
=
new
System.Net.Mail.SmtpClient(server);
client.Credentials
=
new
NetworkCredential(
"
用户名
"
,
"
密码
"
);
client.Send(message);
data.Dispose();
}
引用示例
SendWebMailAndAttach("smtp.126.com");
发表于 @
2006年01月22日 01:22:00
|
评论(
loading...
)
新一篇: asp.net2.0的一些特性(downmoon收集)
|
旧一篇: 获取远程网页的内容之一(downmoon原创)
用户操作
[即时聊天]
[发私信]
[加为好友]
张邀月
订阅我的博客
张邀月的公告
不要淹没在CSDN的海洋!
3w@live.cn
文章分类
Eclipse
Model&Arch
NetBeans
Script&SQL
SharePoint&Office
VS2003
vs2005
Vs2008
VS60
推荐
收藏
C#
Oracle
SharePoint
C#技术资源
MSDN2005中文网站
oliverlu's WebLog
(RSS)
海洋工作室
Oracle技术
SharePoint
Kaneboy's Blog
SharePoint FAQ
WebPart技术与源码
博客堂
常用工具
Java转化C#
Reflector插件
vb转化C#
数据连接串
正则表达式查询
源码世界
脚本专家
我的博客网址
博客园
我宝宝的博客
存档
2009年07月(1)
2009年06月(8)
2009年04月(8)
2009年02月(4)
2009年01月(7)
2008年12月(8)
2008年11月(4)
2008年10月(1)
2008年09月(6)
2008年08月(8)
2008年07月(4)
2008年06月(2)
2008年03月(2)
2008年02月(1)
2008年01月(3)
2007年12月(3)
2007年11月(3)
2007年10月(1)
2007年09月(3)
2007年07月(2)
2007年06月(7)
2007年05月(3)
2007年04月(5)
2007年03月(4)
2007年02月(1)
2007年01月(1)
2006年12月(4)
2006年11月(8)
2006年10月(9)
2006年09月(9)
2006年08月(2)
2006年07月(2)
2006年05月(1)
2006年04月(16)
2006年03月(4)
2006年02月(5)
2006年01月(3)
2005年11月(7)
2005年10月(1)
2005年08月(7)
2005年07月(15)
2005年06月(10)
2003年02月(1)
软件项目交易