点滴积累,融会贯通

-----喜欢一切有兴趣的东西

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  266 随笔 :: 0 文章 :: 404 评论 :: 13 Trackbacks

.net1.1
using System.Web.Mail;
使用:
SendSMTPEMail("100.100.100.100", "someone@xxx.com", "xxxx", "someone@xxx.com", "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("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strFrom);
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", 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", "someone@xxx.com", "xxxx", "someone@xxx.com", "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);
        }

posted on 2007-05-08 16:08 小寒 阅读(1928) 评论(3)  编辑 收藏 所属分类: ASP.NET编程&技巧

评论

在1.1里面怎么发送图片,不是附件类型的。
  回复  引用    

我记得原来在dotnet1.1里面都是用Jmail4.3个人版的破解版,函数非常方便,如果不是群发量很大的话,用起来还是满合适的.
  回复  引用  查看    

#3楼 [楼主] 2007-06-13 16:25 小寒      
也可以用Jmail,或者是ESmtpMail来发送
  回复  引用  查看