欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

.net中 發(fā)送郵件內(nèi)容嵌入圖片的具體實例

 更新時間:2014年02月10日 16:10:20   作者:  
這篇文章主要介紹了.net中 發(fā)送郵件內(nèi)容嵌入圖片的具體實例,需要的朋友可以參考下

例程一


郵件內(nèi)容調(diào)用圖片格式為:<img src=\"cid:Email001\">

發(fā)送郵件的服務(wù)端代碼為:

SmtpClient 發(fā)送郵件的對象 //代碼省略

復(fù)制代碼 代碼如下:

System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.From="發(fā)送者郵箱";
mailMessage.To.Add("收件人郵件列表");
mailMessage.CC.Add("抄送人郵件列表");
mailMessage.Subject = subject;
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(content,null,"text/html");
LinkedResource lrImage = new LinkedResource("a.jpg","image/gif");
lrImage.ContentId = "Email001";
htmlBody.LinkedResources.Add(lrImage);
mailMessage.AlternateViews.Add(htmlBody);
SmtpClient.Send(mailMessage);

例程二

復(fù)制代碼 代碼如下:

SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = "smtp.163.com";
smtp.Credentials = new NetworkCredential("renzhijie1111", "**");

MailMessage mm = new MailMessage();
mm.From = new MailAddress("renzhijie1111@163.com", "無敵任志杰測試");
mm.To.Add("renzhijie1990@vip.qq.com");

mm.Subject = "發(fā)送帶圖片郵件";

string plainTextBody = "如果你郵件客戶端不支持HTML格式,或者你切換到“普通文本”視圖,將看到此內(nèi)容";
mm.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(plainTextBody, null, "text/plain"));

////HTML格式郵件的內(nèi)容
string htmlBodyContent = "如果你的看到<b>這個</b>, 說明你是在以 <span style=\"color:red\">HTML</span> 格式查看郵件<br><br>";
htmlBodyContent += "<a href=\"http://www.dbjr.com.cn//%22%3EVA娛樂網(wǎng)</a> <img src=\"cid:weblogo\">";   //注意此處嵌入的圖片資源
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(htmlBodyContent, null, "text/html");


LinkedResource lrImage = new LinkedResource(@"d:\1.jpg", "image/gif");
lrImage.ContentId = "weblogo"; //此處的ContentId 對應(yīng) htmlBodyContent 內(nèi)容中的 cid: ,如果設(shè)置不正確,請不會顯示圖片
htmlBody.LinkedResources.Add(lrImage);

mm.AlternateViews.Add(htmlBody);

////要求回執(zhí)的標(biāo)志
mm.Headers.Add("Disposition-Notification-To", "renzhijie1111@163.com");

////自定義郵件頭
mm.Headers.Add("X-Website", "http://www.dbjr.com.cn/");

////針對 LOTUS DOMINO SERVER,插入回執(zhí)頭
mm.Headers.Add("ReturnReceipt", "1");

mm.Priority = MailPriority.Normal; //優(yōu)先級
mm.ReplyTo = new MailAddress("renzhijie1111@163.com", "我自己");

////如果發(fā)送失敗,SMTP 服務(wù)器將發(fā)送 失敗郵件告訴我
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

////異步發(fā)送完成時的處理事件
smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);

////開始異步發(fā)送

smtp.SendAsync(mm, null);

相關(guān)文章

最新評論