7

We have a content-managed solution (SDL Tridion, to be specific; however, the question is more general), which includes multiple sites with content of different languages. They all share a number of Razor-based templates, which are used to render HTML fragments with specific injected content when pages are published.

CRM is also managed through the CMS and the same templating is used for the creation of email newsletters. These HTML emails contain images, which are published out to whatever site manages the distribution list in question. Because the templating system is generic and the CMS has no concept of the absolute URLs of the final product, these images are all embedded with relative addresses. We have the capacity to apply an absolute URL as metadata to the different websites in the CMS and write .Net extensions to format these URLs into rendered image tags; however, this would add considerable overhead to this piece of work.

We can resolve this by using a <base href="..." /> tag in the <head> section of the email's markup. This seems to work in Outlook, at least; however, I have not been able to find much up-to-date information on what email clients do and do not support this tag.

The question, then: How widely supported among email clients - particularly browser-based ones - is the <base> tag?

Ant P
  • 24,820
  • 5
  • 68
  • 105
  • It's just a guess, but knowing E-Mail clients, probably not at all. I predict you will end up having to provide absolute URLs somehow – Pekka Jan 30 '13 at 18:35
  • A web-based email will never have a HEAD, because the mail host removes it. Otherwise it would interfere with the page's own HEAD. – Diodeus - James MacFarlane Jan 30 '13 at 18:37
  • @Diodeus - that was my concern. I'm not sure we can get away with not supporting webmail! However, most of the posts I can find regarding this are several years old and I wondered if perhaps browser-based mail providers had gotten a little bit more savvy in the way they process things like this. – Ant P Jan 30 '13 at 18:39
  • Most post on the web about HTML emails say you should have absolute links, though some clients do support the base tag. I think that's your answer, unless you're catering for a specific client like Outlook. – Ruan Mendes Jan 30 '13 at 18:39
  • `` needn't be in `` and *can* be in ``. What support do we have then? – Steven Vachon Dec 20 '16 at 20:50

2 Answers2

9

Unfortunately, it won't work for most web-based email clients (Hotmail, Gmail) and that typically adds up to about 30% of receivers.

Why it won't work: Most web-based clients inject whatever's inside the body tag of your email and strip out everything else, including the head. So, if you send:

<html>
<head><base ...></head>
<body><p class="youremail">Email</p></body>
</html>

The email client does this:

<html>
<head><Email client head></head>
<body>
  <email client wrapper>
  <email>
    <p class="youremail">Email</p>
  </email>
  <email client wrapper>...
</body>

So your base tag will be stripped. Even if it wasn't, since it's not include in the email client's head, it will be ignored by the browser.

Unfortunately, absolute paths on images is the way to go. I have got over similar problems in the past by using a 'preflight processor'. You could use that to get the <base> href and set it on all the images before returning the finished HTML.

Dan Blows
  • 20,846
  • 10
  • 65
  • 96
  • This was our conclusion as well. We currently have a .net extension that hooks into the CMS' rendering of the email and converts internal URIs in tags into the correct relative address on the webserver. We have decided that the best way forward is to modify this to allow a 'base URL' to be pulled from the metadata of each country's site in the CMS. This isn't ideal as we'd have liked this to be more dynamic (it's yet another thing to configure in a behemoth of a solution - heaven forbid we ever have to migrate environments); however, it seems like the only option. – Ant P Feb 06 '13 at 11:02
  • `` needn't be in `` and *can* be in ``. What support do we have then? – Steven Vachon Dec 20 '16 at 20:50
  • @StevenVachon according to the HTML 4 and 5 specs, the base tag can only be included as a child of the head tag. I'm pretty sure most email clients will continue to ignore it wherever you put it, but it's worth testing. – Dan Blows Dec 20 '16 at 21:51
  • @Blowski W3C spec or WHATWG spec? – Steven Vachon Dec 21 '16 at 02:31
  • @StevenVachon W3C, but it's moot anyway as email clients don't follow any kind of public specification. All you can do is reverse engineer their specs by trial and error. – Dan Blows Dec 21 '16 at 08:11
  • W3C specs are for validation mostly. WHATWG specs are implementation specs, which cover all of the forgiving natures of HTML in a web browser. Gmail and Outlook.com are probably going to follow WHATWG more than W3C. In the WHATWG spec, `` is not required to be in ``. – Steven Vachon Dec 21 '16 at 14:00
  • @StevenVachon they don't follow either – Dan Blows Dec 21 '16 at 14:01
  • I know, but still likely more WHATWG than W3C. Though, now that I think of it, it'd be smart of them to strip out `` elements from webmail as to avoid issues with internal links. – Steven Vachon Dec 21 '16 at 18:03
0

I couldn't tell if your using Razor or not, but if you are, you can do this inside a razor view:

src="@Request.Url.GetLeftPart(UriPartial.Authority)~/images/screenshot.png"
toddmo
  • 20,682
  • 14
  • 97
  • 107