zoukankan      html  css  js  c++  java
  • c#发送邮件.net1.1和.net2.0中的两个方法

    .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);
            }

  • 相关阅读:
    TP框架中模板赋值
    使用PHP和GZip压缩网站JS/CSS文件加速网站访问速度
    测试相关知识分享(百度和其他途径查找到的)
    测试基本概念
    shell编程之重定向
    shell编程之函数
    shell编程之循环
    shell编程之测试和判断
    shell编程之变量
    Linux系统学习之正则表达式
  • 原文地址:https://www.cnblogs.com/ymyglhb/p/1263529.html
Copyright © 2011-2022 走看看