ren
ren

Reputation: 93

Including logo when sending email via postal

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: [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>

Upvotes: 1

Views: 854

Answers (2)

Kiran
Kiran

Reputation: 191

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>

Upvotes: 1

Manik Arora
Manik Arora

Reputation: 4792

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.

Upvotes: 5

Related Questions