watchDirectory Help > Plugins > Automatically Email > HTML formatted messages
Sending HTML email
If you want to use rich formatting (bold fonts, colors, etcetera) inside your email messages, you will need to enter a complete HTML document inside the email body. You can use most HTML editors to create the page, and then just copy/paste it into the settings window.
To ensure email clients will recognize the message as an HTML message, the message must contain special headers. WatchDirectory will write those headers only if the message body starts with <html>. When there is even a single space before the <, watchDirectory will not write the necessary headers (exception: see below for attaching extra images).
See the bottom of this page if you want to "Combine HTML Emails".
Using the new file as an image in your emailIf you send this email because a new or changed file is detected, you can attach this file to the message. If the new file is an image, you can "insert" it in your html using this code:
<IMG SRC="cid:message-root.1" ALT="%WD_FILE_N%">
The ".1" inside the SRC link above is a reference to the first attachment of your message. Note that if you use the "-attach" command explained below, you will have to replace ".1" with a higher number.
Using images on a webserverImages on a webserver can be referenced like this:
<IMG SRC="http://www.watchdirectory.net/img/logo_WD.gif" ALT="GdP Software Logo">
There are several disadvantages to use images on your webserver:
- Some email clients will refuse to download them, as those images could be used to track if SPAM is received.
- For the same reason, spam filters will be more likely to consider the message SPAM.
- The receiver must be connected to the internet to see the images
Attaching extra imagesYou can attach extra images to the message by using the attach command at the start of the message body:
-attach filenameFor example:
-attach C:\My Images\Company Logo.jpg -attach C:\My Images\DonaldDuck.gif <html>.....This will attach 2 images to your message. Inside the message body, you can insert these images like this:
Our company logo: <IMG SRC="cid:message-root.1" ALT="Company Logo"> A nice picture of me: <IMG SRC="cid:message-root.2" ALT="Donald"> This is the new file: <IMG SRC="cid:message-root.3" ALT="%WD_FILE_N%">If you also attach the file that triggered this message, that file will be attached after the files you attach with the -attach command. Make sure to use the correct message-number (cid:message-root.3 in the above example) to reference the new file.
The -attach command can be used for local files only, typically on your C: drive.
An example HTML message
<HTML> <HEAD> <TITLE>$RS$: %WD_FILE_N%</TITLE> </HEAD> <BODY> <h1>$RS$: %WD_FILE_N%</h1> <FONT FACE="helvetica"> Hi, there is a new file, called %WD_FILE_N% inside directory %WD_FILE_D% on computer $COMP$! </FONT> Display an image that resides on <a href="http://www.watchdirectory.net/">our web server <BR> <IMG SRC="http://www.watchdirectory.net/img/logo_WD.gif" BORDER="0" WIDTH="76" HEIGHT="64" ALT="GdP Software"></a> <p> Inline display of the new file. Note that "cid" is in lower case. </P> <IMG SRC="cid:message-root.1" ALT="%WD_FILE_N%"> <BR> <FONT FACE="courier"> This line uses COURIER font. <BR> </FONT> <CENTER>This line is centered</CENTER> <BR> <BLINK>This line is blinking</BLINK> <BR> <I>This line is italicized</I> <BR> <B>This line is bold</B> <BR> <TT>This line is teletype font</TT> <BR> <FONT COLOR="#ff0000">This line is RED</FONT> <BR> <FONT COLOR=RED>This line is RED</FONT> <BR> <FONT COLOR=GREEN>This line is GREEN</FONT> <BR> <FONT COLOR=BLUE>This line is BLUE</FONT> <BR> <p> Unordered List follows <UL> <LI> First list item <LI> Second list item <LI> Third list item </UL> </P> <p> Ordered List follows <OL> <LI> First list item <LI> Second list item <LI> Third list item </OL> </P> <p> A "horizontal" rule follows this line. <HR> </P> Thank you! </BODY> </HTML>
Combine HTML Email Messages
As the above example shows, a typical HTML email message looks like this:
1: <html> 2: <head> 3: <title>Hello World</title> 4: </head> 5: <body> 6: New file detected: %WD_FILE% 7: </body> 8: </html>
(The line numbers are there for this explanation only)
When 2 HTML emails are combined, this is what happens:
- Line 7 and 8 are removed from the first message
- A <hr /> tag is appended after line 6
- The line 6 - 8 of the second email are appended to the first email
- The attachments of the second email are added to the first email
- The new body is checked for embedded images (see "Attached Images" further below)
- The "second email", which is now combined with the first email, is removed.
The "Intro" and "Append" text of Combined HTML Emails
Just before the combined email is sent, the following happens:
- The text you enter as "Use the following text as Intro for a combined email" is inserted just after the <body> tag
- The text you enter as "Append the following text after the combined email" is inserted just before the </body> tag.
Attached Images in Combined Emails
As noted above, if you want to reference the attached file as an image, you normally enter something like
<IMG SRC="cid:message-root.1" ALT="%WD_FILE_N%">
where cid:message-root.1 references the first attached file. The obvious problem is that if this email is combined, it will have multiple attached files, and you want to reference the "current" attached file. To make sure the correct image is referenced use the following syntax:
<IMG SRC="cid:message-root.$" ALT="%WD_FILE_N%">
So, you enter a dollar-sign as the attachment number instead.