Neir0
Neir0

Reputation: 13377

Sending html file with images via email

How can i send html mail with images in c#? Can i just set direct link to image on my server(something like <img src="http://mysite.ru/img.png" /> ) or i need attache image and then use link to my attached file? Is there any examples or ready to use libraries? What about css files and scripts?

Upvotes: 3

Views: 6795

Answers (5)

s_h
s_h

Reputation: 1496

probably the best option is to use some package like MvcMailer.

Mvc Mailer display the following characteristics:

MvcMailer sends emails using the MVC views as Email Body with no effort. Here's a quick list of features:

a) Use Razor/WebForms views

b) Use Master pages

c) Write Testable Code

d) Pass values to your view using ViewBag or ViewModel and

e) Generate Absolute URL using Url.Abs method and

f) create multi-part emails by just adding a view file,

g) scaffold your mailers. MvcMailer has a MailerBase class that extends ControllerBase class.

So, Mailers are just like your Controllers. As a result, you can use all the controller goodies without any learning curve, period. The end result is a professional looking HTML email body ready for your to send to your website users.

Visit the Project site for a comprehensive tutorial on MvcMailer. https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide

On the step guid you will find how you can send emails using images.

brgds. sebastian.

Upvotes: 2

rskar
rskar

Reputation: 4657

See http://en.wikipedia.org/wiki/MHTML:

MHTML, short for MIME HTML, is a web page archive format used to combine resources that are typically represented by external links (such as images, Flash animations, Java applets, audio files) together with HTML code into a single file. The content of an MHTML file is encoded as if it were an HTML e-mail message, using the MIME type multipart/related. The first part of the file is normally encoded HTML; subsequent parts are additional resources identified by their original URLs and encoded in base64. This format is sometimes referred to as MHT, after the suffix .mht given to such files by default when created by Microsoft Word, Internet Explorer, or Opera. MHTML is a proposed standard, circulated in a revised edition in 1999 as RFC 2557.

Learning more about MHTML may be the key to solving the problem.

Upvotes: 2

Frazell Thomas
Frazell Thomas

Reputation: 6111

If you directly embed the links into the email (pointing to an external server) you'll get blocked by most clients, but the user can turn them on.

They can be embedded in the usual manner of:

<img src="http://go.com/go.gif" />

If you need it to show up by default you'll need to embed the image as an attachment and link to that attachement inline.

See: http://www.systemnetmail.com/faq/2.6.aspx

Upvotes: 3

Dave
Dave

Reputation: 1244

There are multiple methods of coding in-line images. We use VB.NET in house and this site is an excellent reference http://www.systemnetmail.com/default.aspx

Upvotes: 3

sra
sra

Reputation: 23983

For CSS it is common to use inline style and no referenced files the images on the other side should be just links and not send with the email. You just need to declare the mail content as html and you are ready to go. JavaScript is also available I use it fir some repositioning.

Upvotes: 2

Related Questions