Hardcoding a standard header/footer for html emails

rated by 0 users
This post has 16 Replies | 2 Followers

Celestine
Top 200 Contributor
Posts 108
Points 710
By: Celestine
Posted: Wed, May 28 2008 2:05 PM

I would really like to be able to put in a standard header/footer for html emails -- nothing complicated, just to add some simple styles and a logo, and a "do not reply to this automated email" note in the footer.  I realize this is unsupported, and I don't mind hardcoding it in, I just can't find the right place.

I'm looking for somewhere in the MailGateway.MailRoom component to add something like,

if (email.IsHtml) {
  email.Body = MyHeader + email.Body + MyFooter; }

Any clue where I could put something like this?

 

 
  • Post Points: 20 |
Robert Nash
Top 150 Contributor
Posts 165
Points 4,735
By: Robert Nash
Posted: Wed, May 28 2008 2:29 PM In reply to

Is there a reason why you don't want to update the Languages\en-US\emails\email.xml file?

Cheers,
Rob

Four Roads News

 
  • Post Points: 20 |
afscrome
Top 10 Contributor
Posts 2,728
Points 40,180
TelligentSupportTeam
By: afscrome
Posted: Wed, May 28 2008 2:47 PM In reply to

 I'd also be interested in the solution to such a problem.

The reason I'd be interested in such a feature, and I expect Celestine has the same motivation, I don't want to go and manually edit god knows how many email templates to add exactly the same thing at the begining and end of the messages.

 
  • Post Points: 20 |
Robert Nash
Top 150 Contributor
Posts 165
Points 4,735
By: Robert Nash
Posted: Wed, May 28 2008 2:57 PM In reply to

I see your pain but....

So as a stab in the dark you are talking about a new control panel page, you would still need to edit the email templates to add in markers for the header and footer.  And then you'd have to update probably the mail gateway provider to hook into the mail pipeline and update the message. Also if were put a page into the control panel then you need to be able to configure it for multiple languages.

quite alot of work, I'd just update the email template, it will take about an hour of concentration.

Four Roads News

 
  • Post Points: 20 |
afscrome
Top 10 Contributor
Posts 2,728
Points 40,180
TelligentSupportTeam
By: afscrome
Posted: Wed, May 28 2008 3:45 PM In reply to

It wouldn't have to be a control panel page.  I'd be perfectly happy just updating the mail gateway provider to adjust the email template to be something like

Email Template Body = ResourceManager.GetString("HTMLHeader", "emailresources.xml") + Email Template Body + ResourceManager.GetString("HTMLFooter", "emailresources.xml")

But where to add such code, and if there's anything else to be considered (such as ensuring the resulting email is valid HTML).

 

It would be great if such a feature could be introduced into Community Server as it would make branding the emails Community Server sends out much easier.

 
  • Post Points: 20 |
Robert Nash
Top 150 Contributor
Posts 165
Points 4,735
By: Robert Nash
Posted: Wed, May 28 2008 4:01 PM In reply to

 So if you wanted a relatively quick method then I'd inherit from XmlEmailTemplateProvider and override GetTemplate method.  It returns an EmailTemplate class that again you can subclass so that the constructor updates the xml template data before it is processed. 

Rob

Four Roads News

 
  • Post Points: 20 |
Celestine
Top 200 Contributor
Posts 108
Points 710
By: Celestine
Posted: Wed, May 28 2008 4:47 PM In reply to

Thanks for all the replies!

The reason I don't want to edit emails.xml is, like the previous poster mentioned, I don't want to have to repeat the header/footer for every blasted email, and more importantly, I don't want to have to UPDATE them all if I have a change, either.  It's against my religion.

I don't want to add a page to the control panel.

A nice solution, imho, would be if your header/footer could be defined once within emails.xml, perhaps in the new tags:
<htmlbodyheader>, <htmlbodyfooter>, <textbodyheader>, <textbodyfooter>.  

Using a string from resources.xml is a good second to that, though, but I don't know how long it can be and if it can have html?

I am trying to parse what Rob said... I'm going to give that a crack.

 

 
  • Post Points: 20 |
afscrome
Top 10 Contributor
Posts 2,728
Points 40,180
TelligentSupportTeam
By: afscrome
Posted: Wed, May 28 2008 5:18 PM In reply to

 Let me know how that gets on, I'm very interested in doing the same thing.

A few thoughts to throw in.  I'm thinking as well as the tags you suggested above, maybe a htmlStyles tag might also be needed to add custom css into the email header, so the HTML template comes out like

<HTML>
 <HEAD>
  <STYLE type=text/css>
   [HtmlStyles]
  </STYLE>
 </HEAD>
 <BODY>
  [HtmlBodyHeader]
  [Body]
  [HtmlBodyFooter]
 </BODY>
</HTML>

Secondly, I think it would be best to use a custom resources file instead of resources.xml.  It's very easy to reference such files through code - just use ResourceManager.GetString("Resource Name", "resource file.xml");.  That would help stop the templates you're defining above from being accidently removed in an upgrade.

 
  • Post Points: 20 |
Celestine
Top 200 Contributor
Posts 108
Points 710
By: Celestine
Posted: Wed, May 28 2008 5:19 PM In reply to

I tried this -- in XmlEmailTemplateProvider.cs, in GetTemplate, changed the last line from this:

return new EmailTemplate(emailType, emailTemplates[emailType]);

To this:

 EmailTemplate et;
      et = new EmailTemplate(emailType, emailTemplates[emailType]);
      if (et.IsBodyHtml)
      {
        et.Body += "the end";
      }
      return et;

It didn't work, "the end" is not showing up.  (it doesn't show up if I remove the "if" part either.)

Is this the idea you were trying to get across Rob?  (Except you were saying to do it more elegantly with inheriting and subclassing to leave the original GetTemplate alone.)

 
  • Post Points: 20 |
Celestine
Top 200 Contributor
Posts 108
Points 710
By: Celestine
Posted: Wed, May 28 2008 6:18 PM In reply to

afscrome, I see what you're saying with the HtmlStyles tag.  I was just going to shove a <style> tag in the body; it works there too.  But if you had a way to get in the head you could also use a style sheet.

 

 
  • Post Points: 20 |
Robert Nash
Top 150 Contributor
Posts 165
Points 4,735
By: Robert Nash
Posted: Thu, May 29 2008 2:58 AM In reply to

You need to edit the raw data before it's put into the EmailTemplate object, emailTemplates[emailType] is the thing that yuo need to edit, thats the raw representation of the data that can be altered. 

Rob

Four Roads News

 
  • Post Points: 20 |
Dave
Top 10 Contributor
Posts 2,282
Points 14,405
MVPs
By: Dave
Posted: Thu, May 29 2008 6:28 AM In reply to

Celestine:
afscrome, I see what you're saying with the HtmlStyles tag.  I was just going to shove a <style> tag in the body; it works there too.  But if you had a way to get in the head you could also use a style sheet.

My past experience with HTML emails is that you should always use inline styles as some email readers strip out the style, body, head tags.

What would be good to have is an extra entry in emails.xml which defines the email template with some sort of placeholder where the specific email text appears

 

 

 
  • Post Points: 5 |
Celestine
Top 200 Contributor
Posts 108
Points 710
By: Celestine
Posted: Thu, May 29 2008 2:56 PM In reply to

Robert Nash:

You need to edit the raw data before it's put into the EmailTemplate object, emailTemplates[emailType] is the thing that yuo need to edit, thats the raw representation of the data that can be altered. 

Rob

I'm not following this, Rob, I think emailTemplates[emailType] is just a string of the entire template (including to, from, subject, etc).  Is this right?  I don't know how to access just the htmlbody part of that.

I got slightly closer by changing the body in QueueMessage (in Emails.cs) but at this point the body already contains the </html> tag, so anything I added goes after the </html> tag.  Maybe I need to try ParseTemplate.

Edited: Well I guess not, I can't find ParseTemplate.

 

 

 
  • Post Points: 20 |
Robert Nash
Top 150 Contributor
Posts 165
Points 4,735
By: Robert Nash
Posted: Sat, May 31 2008 4:54 AM In reply to

Yes it is just a string but it is also an XML document, so you can load and manipulate it with XMLDocument class. 

Rob

Four Roads News

 
  • Post Points: 20 |
Celestine
Top 200 Contributor
Posts 108
Points 710
By: Celestine
Posted: Sat, May 31 2008 8:10 AM In reply to

Oh, I hadn't thought of that.  But it just seems like a lot of extra overhead since this must already be done somewhere else.  ParseTemplate maybe but I can't find that code.

 

 
  • Post Points: 20 |
Page 1 of 2 (17 items) 1 2 Next > | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com