国产探花免费观看_亚洲丰满少妇自慰呻吟_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;        }    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永康市| 广水市| 洛隆县| 北安市| 文山县| 白河县| 和平县| 嘉善县| 五河县| 枣庄市| 会理县| 阿拉善盟| 平南县| 扬中市| 莆田市| 沂源县| 浦东新区| 石城县| 柘城县| 昌宁县| 隆昌县| 金阳县| 榆中县| 宁南县| 铁力市| 德令哈市| 通许县| 郁南县| 内江市| 民丰县| 门头沟区| 政和县| 辽宁省| 仙游县| 体育| 本溪市| 阆中市| 容城县| 旬邑县| 济宁市| 双鸭山市|