C#發(fā)送內(nèi)置圖片html格式郵件的方法
更新時(shí)間:2015年04月04日 16:40:46 作者:令狐不聰
這篇文章主要介紹了C#發(fā)送內(nèi)置圖片html格式郵件的方法,涉及C#發(fā)送郵件的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#發(fā)送內(nèi)置圖片html格式郵件的方法。分享給大家供大家參考。具體如下:
下面的代碼用于發(fā)送html格式的郵件,并且可以將圖片附加到郵件一起發(fā)出
MailMessage m = new MailMessage(); m.From = new MailAddress("ir@jb51.net", "Raja Item"); m.To.Add(new MailAddress("su@jb51.net", "Sekaran Uma")); m.Subject = "html email with embedded image coming!"; // Create the HTML message body // Reference embedded images using the content ID string htmlBody = "<html><body><h1>Picture</h1><br><img src=\"cid:Pic1\"></body></html>"; AlternateView avHtml = AlternateView.CreateAlternateViewFromString (htmlBody, null, MediaTypeNames.Text.Html); // Create a LinkedResource object for each embedded image LinkedResource pic1 = new LinkedResource("pic.jpg", MediaTypeNames.Image.Jpeg); pic1.ContentId = "Pic1"; avHtml.LinkedResources.Add(pic1); // Create an alternate view for unsupported clients string textBody = "You must use an e-mail client that supports HTML messages"; AlternateView avText = AlternateView.CreateAlternateViewFromString (textBody, null, MediaTypeNames.Text.Plain); m.AlternateViews.Add(avHtml); m.AlternateViews.Add(avText); // Send the message SmtpClient client = new SmtpClient("smtp.jb51.net"); client.Send(m);
希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
Unity的IFilterBuildAssemblies實(shí)用案例深入解析
這篇文章主要為大家介紹了Unity的IFilterBuildAssemblies實(shí)用案例深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05C#使用WinRar命令進(jìn)行壓縮和解壓縮操作的實(shí)現(xiàn)方法
這篇文章主要介紹了C#使用WinRar命令進(jìn)行壓縮和解壓縮操作的實(shí)現(xiàn)方法,涉及C#基于Process類操作WinRar命令的相關(guān)實(shí)現(xiàn)技巧,代碼簡潔實(shí)用,需要的朋友可以參考下2016-06-06C#使用StringBuilder實(shí)現(xiàn)高效處理字符串
這篇文章主要為大家詳細(xì)介紹了C#如何使用StringBuilder實(shí)現(xiàn)高效處理字符串,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01C#靜態(tài)構(gòu)造函數(shù)用法實(shí)例分析
這篇文章主要介紹了C#靜態(tài)構(gòu)造函數(shù)用法,以實(shí)例形式較為詳細(xì)的分析了C#靜態(tài)構(gòu)造函數(shù)的用途、實(shí)現(xiàn)方法及使用技巧,需要的朋友可以參考下2015-06-06