主頁 > 知識庫 > .net SMTP發(fā)送Email郵件且可帶附件示例

.net SMTP發(fā)送Email郵件且可帶附件示例

熱門標簽:怎么給超市做地圖標注入駐店 十堰正規(guī)電銷機器人系統(tǒng) 寧波自動外呼系統(tǒng)代理 外呼系統(tǒng)費用一年 外呼系統(tǒng)代理品牌 巫師3為什么地圖標注的財寶沒有 手機地圖標注如何刪除 辦理400電話證件 世紀佳緣地圖標注怎么去掉
復(fù)制代碼 代碼如下:

public static void sendEmail(string toAddress, string emailbody)
{
var fromAddress = ConfigurationManager.AppSettings["EmailAddress"];
string fromPassword = ConfigurationManager.AppSettings["EmailPassword"].ToString();
const string subject = "Job Recommendation";


var smtp = new SmtpClient
{
Host = ConfigurationManager.AppSettings["SmtpServer"].ToString(),
Port = int.Parse(ConfigurationManager.AppSettings["SmtpPort"]),
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress, subject, HttpUtility.HtmlEncode(emailbody)))
{
smtp.Send(message);
}
}

add key="EmailAddress" value="**********@gmail.com"/>//Email Address
add key="EmailPassword" value="*********"/> //Emial PWD
add key="SmtpServer" value="smtp.gmail.com"/>
add key="SmtpPort" value="587"/>

--帶附件版本->

var fromAddress = "allenyinj@gmail.com";
string fromPassword = "yj1989120";
const string subject = "CV";


var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress, fromPassword)
};
MailMessage email=new MailMessage(fromAddress, "allen.yin.jun@gmail.com");
email.Subject = "INLINE attachment TEST";
email.IsBodyHtml = true;
string attachmentPath = "C:\\3.jpeg";
Attachment inline = new Attachment(attachmentPath);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
//inline.ContentId = "1";
//inline.ContentType.MediaType = "image/png";
inline.ContentType.Name = Path.GetFileName(attachmentPath);
email.Attachments.Add(inline);
email.Body = "test";
smtp.Send(email);

email.Dispose();

//如果沒有路徑,用Stream

Attachment letter = new Attachment(FileUploadLetter.FileContent, FileUploadLetter.PostedFile.ContentType);
letter.ContentDisposition.Inline = true;
letter.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
//inline.ContentId = "1";
letter.ContentType.MediaType = FileUploadLetter.PostedFile.ContentType;
letter.ContentType.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);
letter.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);

//如果希望通過匿名郵件發(fā)送 則

var smtp = new SmtpClient
{
Host = "serverName",
Port = 25, //匿名發(fā)送端口
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
//Credentials = new NetworkCredential(fromAddress, fromPassword)
};
您可能感興趣的文章:
  • 用Socket發(fā)送電子郵件(利用需要驗證的SMTP服務(wù)器)
  • PHP的一個完整SMTP類(解決郵件服務(wù)器需要驗證時的問題)
  • smtp郵件發(fā)送一例
  • php中通過smtp發(fā)郵件的類,測試通過
  • php下使用SMTP發(fā)郵件的代碼
  • Python httplib,smtplib使用方法
  • PHPMailer郵件類利用smtp.163.com發(fā)送郵件方法
  • 使用SmtpClient發(fā)送郵件的方法
  • C#實現(xiàn)SMTP郵件發(fā)送程序?qū)嵗?/li>
  • SMTP客戶端未通過身份驗證等多種錯誤解決方案分享

標簽:通遼 山西 景德鎮(zhèn) 牡丹江 泰州 嘉興 天門

巨人網(wǎng)絡(luò)通訊聲明:本文標題《.net SMTP發(fā)送Email郵件且可帶附件示例》,本文關(guān)鍵詞  .net,SMTP,發(fā)送,Email,郵件,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《.net SMTP發(fā)送Email郵件且可帶附件示例》相關(guān)的同類信息!
  • 本頁收集關(guān)于.net SMTP發(fā)送Email郵件且可帶附件示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章