2015-04-23 88 views
1

在我的MVC4應用程序中,我使用郵政軟件包發送電子郵件。通過郵件發送電子郵件時包括徽標

我想通過<img>標記包含徽標,但它不起作用。

如何包含我的公司徽標?

控制器動作

public ActionResult Index() 
    { 
     dynamic email = new Email("Example"); 
     email.To = "[email protected]"; 
     email.FunnyLink = "haiii"; 
     email.Send(); 
     return View(); 
    } 

查看

To: @ViewBag.To From: [email protected] 
Subject: Important Message 

<div style="background-color:aqua;"> 
    Hello, You wanted important web links right? 
    Check out this: @ViewBag.FunnyLink 

    <br /> 
    <img src="~/Images/Logo.png" /> 
</div> 

回答

5

您需要使用完整的絕對圖像的URL喜歡這 -

<img src="@Request.Url.GetLeftPart(UriPartial.Authority)/Images/Logo.png" /> 

如果您有任何基於HTML文件,那麼你應該送域名就像你傳遞到視圖喜歡這個 -

<img src="@ViewBag.DomainName/Images/Logo.png" /> 

當你的郵件會被用戶接收,則其它數據電子郵件的內容將不會解決從相對URL圖像路徑是這樣 -

/Images/logo.png {this will not work} 

所以圖像只能是如果有全域路徑牽強。

1

您可以使用如下所示的Html擴展名。您可以參考here瞭解更多詳情。

<div style="background-color:aqua;"> 
    Hello, You wanted important web links right? 
    Check out this: @ViewBag.FunnyLink 

    <br /> 
    @Html.EmbedImage("~/Images/Logo.png") 
</div>