Chinaunix首页 | 论坛 | 博客
  • 博客访问: 944604
  • 博文数量: 264
  • 博客积分: 10107
  • 博客等级: 上将
  • 技术积分: 2455
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-09 16:34
文章分类

全部博文(264)

文章存档

2012年(1)

2011年(11)

2010年(128)

2009年(82)

2008年(42)

我的朋友

分类:

2009-09-17 15:40:11

.net1.1
using System.Web.Mail;
使用:
SendSMTPEMail("100.100.100.100", "", "xxxx", "", "webtest", TextBox1.Text, null, null);
方法体:
public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody, string bcc, string cc)
        {
            System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
            mail.BodyFormat = MailFormat.Html;
            mail.From = strFrom;
            mail.To = strto;    //多个收件人之间用分号分割
            mail.Bcc = bcc;
            mail.Cc = cc;
            mail.Subject = "mail test!!!";
            mail.Body = TextBox1.Text;
            mail.Fields.Add("", "1");
            mail.Fields.Add("", strFrom);
            mail.Fields.Add("", strFromPass);

            System.Web.Mail.MailAttachment attachment = new System.Web.Mail.MailAttachment("c:\\log.log");
            mail.Attachments.Add(attachment);
            SmtpMail.SmtpServer = strSmtpServer;
            SmtpMail.Send(mail);
        }
.net2.0
using System.Net.Mail;
使用:
SendSMTPEMail("100.100.100.100", "", "xxxx", "", "webtest", TextBox1.Text, null, null);
方法体:
 public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
        {
            System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strFrom, strto, strSubject, strBody);
            System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment("c:\\log.log");
            message.Attachments.Add(attachment);
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = true;
            client.Send(message);
        }

 

 

 

----------------------------------------------------

采用第一种方法,需要添加对“System.Web.dll”的引用。

阅读(950) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~