4

How do you use MVCMailer to embed an image into a email?

I've tried something along the lines of

<img src="@Url.Abs("\\..\\images\logo.png")" \> 

with no success.

Any examples?

Thanks

woggles
  • 7,444
  • 12
  • 70
  • 130

3 Answers3

5

Look at the MvcMailer wiki

https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide

search for Embed Image and you'll and you are done!

Sohan
  • 3,757
  • 2
  • 24
  • 24
  • Hi, When you write resources["logo"] = logoPath; in the wiki, is it the http url inside logoPath? I need to embed image for example as base64 inside the mail. Is it possible ? – Dragouf Jan 09 '12 at 09:55
  • @Dragouf if you need to embed image as base64 you don't need this LinkedResources collection. Simply craft in your MvcMailers' html template – tomalone Nov 07 '17 at 20:01
3

Try like this:

<img src="@Url.Abs(Url.Content("~/images/logo.png")" /> 

Also make sure that the absolute url that is generated by this helper is accessible when you open the email in your mail client. For example if you hosted your ASP.NET MVC application in the local visual studio web server ensure that it is running when you try to read the email as the image must be accessible.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

You have to type the entire URL where your image is, and also it has to be hosted online.

So for example , i want to embed the image that is called Logo.png and it's located in the folder Images in my project , i'll write in the view of my MvcMailer:

<img src="http://mywebsite.com/Images/Logo.png" />
mejiamanuel57
  • 6,807
  • 1
  • 32
  • 34