andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 168 forks source link

Style attribute for embedded image #109

Open denisz1 opened 9 years ago

denisz1 commented 9 years ago

When styling emails, it is necessary to use inline styles in the style attribute, because webmail services (gmail and friends) strip out stylesheets.

The @Html.EmbedImage extension method can render the alt attribute, but not a style attribute. So I can't style my images.

The signature could be changed from:

public static IHtmlString EmbedImage(this HtmlHelper html, string imagePathOrUrl, string alt = "")

to:

public static IHtmlString EmbedImage(this HtmlHelper html, string imagePathOrUrl, string alt = "", string style= "")

And the final line from:

return new HtmlString(string.Format("<img src=\"cid:{0}\" alt=\"{1}\"/>", linkedResource.ContentId, html.AttributeEncode(alt)));

to:

return new HtmlString(string.Format("<img src=\"cid:{0}\" alt=\"{1}\" style="{2}"/>", linkedResource.ContentId, html.AttributeEncode(alt), html.AttributeEncode(style)));

What do you think?

denisz1 commented 9 years ago

I've added a PR.

ghost commented 9 years ago

upvote

jnis77diver commented 8 years ago

+1

jeffreyharris commented 7 years ago

Can someone tell me the syntax for the @HTML embed image tag with styles applied? For example, how would you add styles to this:

@Html.EmbedImage("~/Content/graphics/global/logo.png")