.net SMTP發(fā)送Email實(shí)例(可帶附件)_.Net教程
推薦:js實(shí)現(xiàn)廣告漂浮效果的小例子這篇文章介紹了在JS中廣告漂浮效果的實(shí)現(xiàn)代碼,有需要的朋友可以參考一下 復(fù)制代碼 代碼如下: html head meta http-equiv=Content-Type content=text/html; charset=gb2312 / title/title style type=text/css div{ position:absolute; } /style /head body div id=floa
本文為大家詳細(xì)介紹下.net SMTP發(fā)送Email同時(shí)可帶附件的具體實(shí)現(xiàn)思路及代碼,想實(shí)現(xiàn)的朋友可以參考下哈,希望對(duì)大家有所幫助 復(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 = "[email protected]";
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, "[email protected]");
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();
//如果沒(méi)有路徑,用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);
分享:asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)以下為設(shè)計(jì)步驟: 1、在C# 中連接數(shù)據(jù)庫(kù)。如下圖: 2、在項(xiàng)目中添加新建項(xiàng),建立一個(gè)數(shù)據(jù)集,并把Categories從服務(wù)器資源列表中拖到這個(gè)數(shù)據(jù)集模板中并點(diǎn)擊菜單生成-生成解決方案,如下圖: 3、在aspx的webform上放一個(gè)ObjectDataSource控件,設(shè)定它的TypeName為剛剛
- asp.net如何得到GRIDVIEW中某行某列值的方法
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無(wú)刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見(jiàn)代碼存在的偽造IP問(wèn)題探討
- VS2010 水晶報(bào)表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(kù)(連接字符串的配置及獲取)
- asp.net頁(yè)面?zhèn)髦禍y(cè)試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過(guò)程實(shí)現(xiàn)分頁(yè)示例代碼
- 模板無(wú)憂:在.NET開發(fā)中靈活使用TreeView控件
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- asp.net中javascript的引用(直接引入和間接引入)
- Request.UrlReferrer使用詳解
- asp.net里面的身份驗(yàn)證和授權(quán)
- ASP.NET中“找不到指定模塊”的解決辦法
- 在網(wǎng)頁(yè)中動(dòng)態(tài)的生成一個(gè)圖片
- 揭秘6條ASP.NET編程實(shí)用技巧
- .NET平臺(tái)依賴注入機(jī)制及IoC的設(shè)計(jì)與實(shí)現(xiàn)
- .Net基礎(chǔ)之了解ASP.NET中的IFRAME框架掛馬
- Asp.net ajax實(shí)現(xiàn)任務(wù)提示頁(yè)面
- “/”應(yīng)用程序中的服務(wù)器錯(cuò)誤及解決方法
- 相關(guān)鏈接:
- 教程說(shuō)明:
.Net教程-.net SMTP發(fā)送Email實(shí)例(可帶附件)
。