How to CFMAIL Properly and Keep the SPAM in the Can
One of the most commonly used ColdFusion tags may also be one of the most misused. I say this because of the ColdFusion code that I've seen in production. It appears that a large number people think that all you need to do is open the CFMail tag and type in a to address the from address a subject and then close the tag. And then stuff your email message between the opening and closing tags. People do it this way as this is how they are shown, see the examples below.
<cfmail to = "#form.mailto#"
from = "#form.mailFrom#"
subject = "#form.subject#">
This message was sent by an automatic mailer built with cfmail:
= = = = = = = = = = = = = = = = = = = = = = = = = = =
#form.body#
</cfmail>
Common blog example found via a typical Google search:
<cfmail
to = "name@yourdomain.com"
from = "name@yourdomain.com"
subject = "Example of CFMail Tag using Coldfusion 5.0"
server = "mail.yourdomain.com">
Email Message
</cfmail>
While both examples are technically correct and will send an email from your ColdFusion server they all lack what most people are trying to achieve in sending HTML formatted/pretty email messages and messages with attachments. There are precise ways in which the RFC (RFC-822) standard for sending e-mails dictates that these are to be done and ColdFusion allows you to follow the standard exactly. You just need to know how. I am not going to bore you with the RFC standard details, however if you are suffering from insomnia feel free to read them. What I will show you is how to send an HTML formatted email with the proper email message parts and optional file attachments so that it will safely pass most if not all SPAM filter tests and will render properly in mail clients.
The above code would generate email that looked like this when you examine the raw email source.
Delivered-To: myaddress@mydomain.com
X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on
mail.mymailserver.com
X-Spam-Level: **
X-Spam-Status: No, score=2.8 required=5.0 tests=HTML_MESSAGE,
HTML_MIME_NO_HTML_TAG,MIME_HTML_ONLY,RDNS_NONE autolearn=no version=3.2.4
Message-ID: <1331187905.1191260207349870.JavaMail.root@mail.mymailserver.com>
Date: Mon, 7 Dec 2009 11:35:39 -0600 (CST)
From: John Doe <some_address@somedomain.com>
Reply-To: some_address@somedomain.com
To: myaddress@mydomain.com
Subject: Hows life
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
John Doe,<br><br>
Just wondering how things are going.
Looks good, right? However, there are some issues. There are HTML tags in the body of the message, but there is no text portion of the message. If you notice the header information you will see an item for X-Spam-Status and this indicates a score of 2.8. This score was not high enough yet to dictate that this was SPAM according to this SPAM servers rules (on other email servers it might get flagged as SPAM), but you will notice that the items it flagged were almost all HTML related items such as HTML only. In order to reduce the SPAM score you need to properly format your email messages.



