繁体中文
设为首页
加入收藏
当前位置:ASP技术首页 >> ASP基础 >> 使用 System.Web.Mail发送邮件

使用 System.Web.Mail发送邮件

2005-11-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介://simple email MailMessage mail = new MailMessage(); mail.To = "me@mycompany.com"; mail.From = "you@yourcompany.com"; mail.Subject = "this is a test email."; mail.Body = "this is my test email bod...
关键字:邮件 System Mail Web

//simple email

MailMessage mail = new MailMessage();

mail.To = "me@mycompany.com";

mail.From = "you@yourcompany.com";

mail.Subject = "this is a test email.";

mail.Body = "this is my test email body";

SmtpMail.SmtpServer = "localhost"; //your real server goes here

SmtpMail.Send( mail );

//simple Html email

MailMessage mail = new MailMessage();

mail.To = "me@mycompany.com";

mail.From = "you@yourcompany.com";

mail.Subject = "this is a test email.";

mail.BodyFormat = MailFormat.Html;

mail.Body = "this is my test email body.
this part is in bold";

SmtpMail.SmtpServer = "localhost"; //your real server goes here

SmtpMail.Send( mail );

//email with attachments

MailMessage mail = new MailMessage();

mail.To = "me@mycompany.com";

mail.From = "you@yourcompany.com";

mail.Subject = "this is a test email.";

mail.Body = "this is my test email body.";

MailAttachment attachment = new MailAttachment( Server.MapPath( "test.txt" ) ); //create the attachment

mail.Attachments.Add( attachment ); //add the attachment

SmtpMail.SmtpServer = "localhost"; //your real server goes here

SmtpMail.Send( mail );

//change the TO address to a friendly name

mail.From = "\"John Smith\" ";

//multiple recipients

mail.To = "me@mycompany.com;him@hiscompany.com;her@hercompany.com";

责任编辑:admin
相关文章