a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

c# SendMail發(fā)送郵件實(shí)例代碼

2020-01-24 03:10:16
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Text;

namespace Common
{
    /// <summary>
    /// 基于system.net.mail發(fā)送郵件,支持附件
    /// </summary>
    public class NetSendMail
    {
        public static void MailSend(string mailFrom, string maiFromlAccount, string mailFromPwd, string mailSmtpServer, IList<string> mailTo, IList<string> mailCC, IList<string> mailBCC, string mailTitle, string mailContent, IList<string> mailAttachments, System.Text.Encoding encoding, bool isBodyHtml)
        {
            MailMessage message = new MailMessage();
            if (mailFrom.Trim() == "")
            {
                throw new Exception("發(fā)送郵件不可以為空");
            }
            message.From = new MailAddress(mailFrom);
            if (mailTo.Count <= 0)
            {
                throw new Exception("接收郵件不可以為空");
            }
            foreach (string s in mailTo)
            {
                message.To.Add(new MailAddress(s));
            }
            if (mailCC.Count > 0)
            {
                foreach (string s in mailCC)
                {
                    message.CC.Add(new MailAddress(s));
                }
            }
            if (mailBCC.Count > 0)
            {
                foreach (string s in mailBCC)
                {
                    message.Bcc.Add(new MailAddress(s));
                }
            }
            message.Subject = mailTitle;
            message.Body = mailContent;
            message.BodyEncoding = encoding;   //郵件編碼
            message.IsBodyHtml = isBodyHtml;      //內(nèi)容格式是否是html
            message.Priority = MailPriority.High;  //設(shè)置發(fā)送的優(yōu)先集
            //附件
            foreach (string att in mailAttachments)
            {
                message.Attachments.Add(new Attachment(att));
            }
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = mailSmtpServer;
            smtpClient.Credentials = new NetworkCredential(maiFromlAccount, mailFromPwd);
            smtpClient.Timeout = 1000;
            smtpClient.EnableSsl = false;        //不使用ssl連接
            smtpClient.Send(message);
        }

        public static void MailSendText(string mailFrom, string maiFromlAccount, string mailFromPwd, string mailSmtpServer, IList<string> mailTo, IList<string> mailCC, IList<string> mailBCC, string mailTitle, string mailContent)
        {
            List<string> attList = new List<string>();
            MailSend(mailFrom, maiFromlAccount, mailFromPwd, mailSmtpServer, mailTo, mailCC, mailBCC, mailTitle, mailContent, attList, Encoding.UTF8, false);
        }

        public static void MailSendHTML(string mailFrom, string maiFromlAccount, string mailFromPwd, string mailSmtpServer, IList<string> mailTo, IList<string> mailCC, IList<string> mailBCC, string mailTitle, string mailContent)
        {
            List<string> attList = new List<string>();
            MailSend(mailFrom, maiFromlAccount, mailFromPwd, mailSmtpServer, mailTo, mailCC, mailBCC, mailTitle, mailContent, attList, Encoding.UTF8, true);
        }
    }
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 2019天天操 | 中文字幕 亚洲一区 | 欧美在线一级 | 日韩精品专区在线影院重磅 | 欧美日韩成人在线播放 | 日本中文字幕一区 | 日本三级国产 | 在线观看国产 | 一级性视频 | 国产高清精品一区二区三区 | 亚洲毛片网站 | 一级片视频免费 | 中文字幕亚洲一区二区三区 | 国产无套一区二区三区久久 | 久久51| 9191视频| 国严精品久久久久久亚洲影视 | 在线视频自拍 | 久久国产一区二区 | 青草精品| 日韩成人精品 | а天堂中文最新一区二区三区 | www.免费看黄 | 日韩欧美一级精品久久 | 欧美三级黄 | 国产一区二区精品在线 | 中文字幕三级在线看午夜 | 欧美日韩精品一区二区 | 狠狠入ady亚洲精品经典电影 | 国产又粗又猛视频免费 | 久久伦理电影网 | 久久99国产精品久久99大师 | 久久亚洲一区二区三区四区 | 日韩欧美一区二区三区视频 | 麻豆视频在线 | 999久久久 | 亚洲国产成人综合 | 国产午夜精品视频 | 国产精品久久久久久久7电影 | av在线播放观看 | 伊人影院在线观看 |