Attaching HTML signatures

MDaemon’s content filter has an “Append a corporate signature” rule which can be used to add a block of text to the bottom of message.  However, if you attempt to use HTML, the HTML code gets inserted into plain text signatures too.

I created a content filter rule hack around this limitation.

Basically what this rule does is the following:

Action01) Add the “plain-text” version of the signature with a special tag (/zzz/)
Action02) Clean up the special tag from the plain-text version.
Action03) Remove most of the signature from the HTML version.
Action04) Remove the rest of the signature from the HTML version and insert the HTML signature.

So, if you’re feeling brave, backup your \MDaemon\App\ directory and get started.

To “install” this content filter rule, copy the below lines and paste them into the very top of very bottom of your \MDaemon\App\cfrules.dat file, then go into MDaemon’s Content Filter and activate the rule.

[Rule001]
RuleName=HTML sig - TEST RULE
Enable=No
ThisRuleCondition=All
ProcessQueue=BOTH
Condition01=FROM|contains local account|AND|
Action01=add footer|"/zzz/1 corporate signature/zzz/","/zzz/2 corporate signature/zzz/","/zzz/3 corporate signature/zzz/"
Action02=body search and replace|"^/zzz/(.*)/zzz/$","\1","0,1"
Action03=body search and replace|"(<br>|^)/zzz/.*/zzz/<br>","","0,1"
Action04=body search and replace|"(<br>|^)/zzz/.*/zzz/</html>","<br><font color="#ff0000"><i>1 corporate signature</i></font><br><font color="#3366ff" size="-2">2 corporate signature</font><br><a href="http://www.example.com/">3 corporate signature</a><br></html>","0,1"

The rule is hardcoded to only function if a message is FROM a local account, but you’ll want to test this in your environment to make sure that no other mail gets a signature added. I’d suggest adding a “If the TO HEADER contains” condition to test the rule.

After “installing” the rule, open the rule in the Content Filter GUI editor (MDaemon –> Security –> Content Filter), edit the rule, then edit the “then add footer” (Action01) section to contain your corporate signature. However, add a /zzz/ to the start and end of each line. In other words, if you want your signature to look like this:


My Name
My Title
My Company
www.example.com

then what you’d enter would be

/zzz/– /zzz/
/zzz/My Name/zzz/
/zzz/My Title/zzz/
/zzz/My Company/zzz/
/zzz/www.example.com/zzz/

Don’t worry, the /zzz/ won’t show up to users, this is just a trick to allow the following actions to identify the signature. Action02 cleans up the /zzz/ code from the plain text version.

Action03 and Action04 are where the “magic” happens, these actions modify the HTML portion of the message and remove the signature we just finished adding, and then Action04 adds the HTML version of the signature.

Edit the very last “and body – search and replace” condition, don’t touch the “Search Expression” at all, only change the “Replace With”, replace it with your corporate signature, and add a tag to the end.

Hopefully this works, it appears to work in my own testing, but I’d appreciate comments if you either are successful, or can’t get it working. Please comment here, don’t use the “Feedback” link requesting technical support.

Note that while you can add HTML, it’s not yet possible to add a corporate logo — You can link to an image on the web, but many/most mail clients won’t display said image.

UPDATED (2011/02/01): Made minor tweaks to content filter rule

CC BY-NC-ND 4.0 Attaching HTML signatures by Dave Warren (everything-mdaemon.com) is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

18 Replies to “Attaching HTML signatures”

  1. Hey,

    Thanks a lot for this, been trying to find out how to use HTML signatures for a while!

    Say for example, I’m trying to add a small company logo to it, is it possible to attach a hyperlink for an image?

  2. Oh, please ignore my last question, I failed to notice that images are not yet working.

    I might play around with this a little and see if it’s possible to get it working.

    Thanks a lot!

  3. Grant, hyperlinking to an image works great, except that most modern mail clients won’t show the image unless the user clicks the “Show remote images” button (or equivalent)

    In theory, appending an attachment is probably possible, but I haven’t found a way to do so reliably yet.

  4. I’ve completely disabled Content Filter from the options, but CFEngine.exe still takes 90% of the CPU resources when there are a bunch of messages in queue, I can’t understand why CFEngine.exe is still being executed?

  5. Waseem, CFEngine is responsible for a lot more then just user created content rules.

    Among other things, CFEngine is responsible for MDaemon’s antivirus, spam filtering, DK/DKIM signing, as well as hashcash.

    I’d suggest looking at your hashcash settings, if you’re signing outbound messages with hashcash tokens then you’ll definitely see high CPU usage as hashcash is intentionally CPU intensive.

  6. is it possible query Active Directory to add as signature the information like name surname title telephone number ect?

  7. Hi,

    I tried your codings exactly as is but didn’t work as expected. The recipient received the email with the signature of a single line below:

    /zzz/3 corporate signature/zzz/

    Appreciate if you could enlighten me what could have gone wrong?

    vic

  8. What if i wanted to add a hyperlink to the word

    “give today” under the outgoing signature ?? someone please help

  9. Can you someone help please i want to add this to my corporate signature but part of the word should be hyperlinked

    Please would you like to Give today! but i want the word “Give today!” to be hyperlink to http://www.yahoo.com

  10. Solomon, are you asking how to construct the HTML itself it something else?

  11. I have an interesting issue here – as soon as I use the add footer rule in cfrules.dat it breaks the automatic wrapping of text and the e-mail falls back to wrapping a 1024 characters rather than 75.

    I’m pretty confident that this is a bug with MDaemon and have logged it with my vendor as such, but would be interested to know if anyone else has experienced similar.

  12. From what I know you’ll have to manually wrap signatures for now, MDaemon’s signature feature doesn’t force word-wrapping (but since it only deals with complete lines, you can insert linewraps at the 72-80 character point as you desire)

  13. Dave, thanks.

    What seems to happen is that as soon as you use the content filter rules, the *existing* wrapping becomes corrupted… I can show you some examples of what I mean if you’d like, I think it’s a bug with the cfrules processing because it doesn’t matter if you don’t even attempt to insert new HTML, if you say, a search and replace on a string, the *existing* Outlook-generated HTML becomes unwrapped too.

    Steve

  14. Oh interesting. I haven’t seen that behaviour before, but I’ll test a bit to see if I can reproduce it in the lab. MDaemon 11.0.3?

  15. I’ve done a ton of testing here and I can’t find any way that existing HTML gets unwrapped.

    For testing I’m freezing my “Inbound” queue (which allows me to review the message before the content filter touches it) and again after the content filter rule.

    In all cases, the message is wrapped the same before and after the content filter runs, the only significant difference is the signature that I’m adding.

    Note that creating a message that is too long is easy, copy/pasting seems to result in   rather than a normal space being inserted, resulting in a too-long line. I’m not sure what can be done though, we can’t insert whitespace randomly in content.

    Either way, this content filter rule doesn’t seem to cause issues.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.