2017-08-04 127 views
-4

大家好我在學習學習編程的中間只是爲了通知你,我不想提前學習所以這裏是我的問題是當發送電子郵件使用流暢的電子郵件,Gmail不會顯示我的嵌入式圖像,當我檢查元素時,它只顯示空的img標籤,但我可以附加圖像,但不幸的是我不能在電子郵件內嵌入圖像我到目前爲止做了一些研究這是結果。發送電子郵件與嵌入式圖像,圖像不顯示在Gmail中

我在這裏使用的模板和我發送的圖像是90 x 90並有JPG擴展名。

   string authorImage = HttpContext.Current.Server.MapPath(@"~/img/author.jpg"); 

       Attachment authorImageAtt = new Attachment(authorImage); 

       authorImageAtt.ContentDisposition.Inline = true; 
       authorImageAtt.ContentDisposition.DispositionType = DispositionTypeNames.Inline; 

       string authorImageId = "author"; 
       authorImageAtt.ContentId = authorImageId; 

       model.ImgSrc = authorImageId; 

       var template = 
       System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(string.Format("~/Templates/{0}.cshtml", emailTemplate))); 
       var body = Razor.Parse(template, model); 

       var email = Email 
       .From("[email protected]") 
       .To(model.EmailTo) 
       .Subject(subject) 
       .Attach(authorImageAtt) 
       .Body(body).BodyAsHtml(); 
       email.Send(); 

該視圖。

@model MYAPP.Site.Models.Author 

<h2>Image Below</h2> 

<img src="cid:@Model.ImgSrc" /> 

我是怎麼錯過了,我會很感激任何人都可以點我在正確的道路 也是我在當地的發展。

+1

請添加代碼到問題的代碼,而不是作爲一個圖像 – ASpirin

+0

請添加代碼 –

+0

https://stackoverflow.com/questions/18358534/send-inline-image-in-email – Etienne

回答

0

正如@Etienne(計算器後)寫在評論

mail.IsBodyHtml = true;

應該足夠了這裏。

相關問題