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

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

C# 發郵件類可發送附件

2019-11-17 01:42:48
字體:
來源:轉載
供稿:網友

C# 發郵件類可發送附件

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Net.Mail;namespace Ajax.發郵件{    public class GetMail    {         //MailAddress ds = new MailAddress("1738819932@QQ.com");         //   Send(ds, "674580075@qq.com", "郵件主題", "郵件內容","附件名稱");        public GetMail()        { }             /// <summary>        /// 發送電子郵件        /// </summary>        /// <param name="MessageFrom">發件人郵箱地址</param>        /// <param name="MessageTo">收件人郵箱地址</param>        /// <param name="MessageSubject">郵件主題</param>        /// <param name="MessageBody">郵件內容</param>        /// <param name="SUpFile">附件</param>        /// <returns></returns>        public bool Send(MailAddress MessageFrom, string MessageTo, string MessageSubject, string MessageBody, string SUpFile)        {            MailMessage message = new MailMessage();            message.From = MessageFrom;            message.To.Add(MessageTo); //收件人郵箱地址可以是多個以實現群發            message.Subject = MessageSubject;            message.Body = MessageBody;            if (SUpFile != "")            {                               SUpFile = Server.MapPath("~/發郵件/Upfile/" + SUpFile);//獲得附件在本地地址                //將文件進行轉換成Attachments                Attachment data = new Attachment(SUpFile, MediaTypeNames.application.Octet);                // Add time stamp information for the file.                ContentDisposition disposition = data.ContentDisposition;                disposition.CreationDate = System.IO.File.GetCreationTime(SUpFile);                disposition.ModificationDate = System.IO.File.GetLastWriteTime(SUpFile);                disposition.ReadDate = System.IO.File.GetLastaccessTime(SUpFile);                message.Attachments.Add(data);                System.Net.Mime.ContentType  ctype=new System.Net.Mime.ContentType ();             }            message.IsBodyHtml = true; //是否為html格式            message.PRiority = MailPriority.Normal; //發送郵件的優先等級            SmtpClient sc = new SmtpClient();            sc.Host = "smtp.qq.com"; //指定發送郵件的服務器地址或ip            sc.Port = 25; //指定發送郵件端口            sc.Credentials = new System.Net.NetworkCredential("發送郵箱賬號", "賬號密碼"); //指定登錄服務器的try            {                sc.Send(message); //發送郵件            }            catch            {                return false;            }            return true;        }    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长宁区| 福海县| 鹤峰县| 浦江县| 桐柏县| 临澧县| 盈江县| 桂平市| 无棣县| 玉环县| 景泰县| 昭通市| 红原县| 西青区| 台山市| 温宿县| 阜城县| 休宁县| 含山县| 乌鲁木齐市| 阿图什市| 沂源县| 武安市| 根河市| 林甸县| 景德镇市| 兴山县| 泰和县| 包头市| 刚察县| 永平县| 正镶白旗| 库尔勒市| 什邡市| 教育| 双城市| 宝清县| 永济市| 怀宁县| 肇源县| 大同市|