日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# 发邮件类可发送附件

發布時間:2025/3/15 C# 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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);//獲得附件在本地地址//將文件進行轉換成AttachmentsAttachment 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"; //指定發送郵件的服務器地址或IPsc.Port = 25; //指定發送郵件端口sc.Credentials = new System.Net.NetworkCredential("發送郵箱賬號", "賬號密碼"); //指定登錄服務器的try{sc.Send(message); //發送郵件 }catch{return false;}return true;}} }

?

轉載于:https://www.cnblogs.com/xiao-bei/p/3928959.html

總結

以上是生活随笔為你收集整理的C# 发邮件类可发送附件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。