【问题标题】:Including logo when sending email via postal通过邮政发送电子邮件时包括徽标
【发布时间】:2015-04-23 04:43:25
【问题描述】:

在我的 MVC4 应用程序中,我使用邮包来发送电子邮件。

我试图通过<img> 标签包含一个徽标,但它不起作用。

如何包含我的公司徽标?

控制器动作

   public ActionResult Index()
   {
       dynamic email = new Email("Example");
       email.To = "xxxxx@xxxxxx";
       email.FunnyLink = "haiii";
       email.Send();
       return View();
   }

查看

 To: @ViewBag.To From: lolcats@website.com 
 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>

【问题讨论】:

    标签: asp.net-mvc-4 postal


    【解决方案1】:

    您需要像这样使用完整的绝对图片网址-

    <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}
    

    因此,只有在具有完整域路径的情况下才能获取图像。

    【讨论】:

      【解决方案2】:

      您可以使用 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-16
        • 2022-01-13
        • 1970-01-01
        • 2012-01-07
        相关资源
        最近更新 更多