1

In my MVC4 application, I am using the postal package for sending emails.

I am trying to include a logo via an <img> tag, but it's not working.

How can I include my company logo?

Controller Action:

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

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>
Brendan Green
  • 11,676
  • 5
  • 44
  • 76
ren
  • 93
  • 12

2 Answers2

5

You need to use full absolute image urls like this-

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

or

If you're having html based files then you should send the domain name just like the other data you're passing into the view like this-

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

When your email would be received by the users then the content of your email would not resolve the image path from relative urls like this -

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

So the images can only be fetched if having full domain path.

Manik Arora
  • 4,702
  • 1
  • 25
  • 48
1

You could use Html extension as shown below. You can refer here for more details.

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

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