国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASP.NET發送電子郵件

2019-11-14 14:33:45
字體:
來源:轉載
供稿:網友

代碼:

using System;using System.Collections.Generic;using System.Configuration;using System.Linq;using System.Net.Mail;using System.Text;namespace Common.Utils{    /// <summary>    /// 郵件工具類    /// </summary>    public class EmailUtil    {        #region 發送郵件        /// <summary>        /// 發送郵件        /// 例:bool result = EmailUtil.SendEmail("857385896@QQ.com", "請審核報告", "請及時審核報告");        /// </summary>        /// <param name="mailTo">要發送的郵箱</param>        /// <param name="mailSubject">郵箱主題</param>        /// <param name="mailContent">郵箱內容</param>        /// <returns>返回發送郵箱的結果</returns>        public static bool SendEmail(string mailTo, string mailSubject, string mailContent)        {            // 設置發送方的郵件信息,例如使用網易的smtp            string smtpServer = ConfigurationManager.AppSettings["smtpServer"]; //SMTP服務器 例:smtp.163.com            string mailFrom = ConfigurationManager.AppSettings["mailUserName"]; //登陸用戶名 例:s847577@163.com            string userPassWord = ConfigurationManager.AppSettings["mailPwd"]; //登陸密碼    例:fjia345f            // 郵件服務設置            SmtpClient smtpClient = new SmtpClient();            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定電子郵件發送方式            smtpClient.Host = smtpServer; //指定SMTP服務器            smtpClient.Credentials = new System.Net.NetworkCredential(mailFrom, userPassword);//用戶名和密碼            // 發送郵件設置                    MailMessage mailMessage = new MailMessage(mailFrom, mailTo); // 發送人和收件人            mailMessage.Subject = mailSubject;//主題            mailMessage.Body = mailContent;//內容            mailMessage.BodyEncoding = Encoding.UTF8;//正文編碼            mailMessage.IsBodyHtml = true;//設置為HTML格式            mailMessage.PRiority = MailPriority.Low;//優先級            try            {                smtpClient.Send(mailMessage); // 發送郵件                return true;            }            catch (SmtpException ex)            {                return false;            }        }        #endregion    }}
View Code

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 增城市| 南康市| 肇庆市| 株洲县| 荔波县| 噶尔县| 合阳县| 会昌县| 开远市| 清水河县| 炉霍县| 昌黎县| 乌兰察布市| 苏州市| 紫金县| 封丘县| 郧西县| 汝城县| 涟源市| 丹阳市| 鹤庆县| 增城市| 留坝县| 鄂伦春自治旗| 塔城市| 永福县| 犍为县| 绥德县| 新源县| 宜良县| 理塘县| 镇平县| 徐汇区| 南昌县| 海安县| 西平县| 托里县| 泾源县| 甘南县| 宝鸡市| 高阳县|