Created
March 25, 2014 11:17
-
-
Save bennadel/9759687 to your computer and use it in GitHub Desktop.
Monitoring The ColdFusion Mail Server With GMail And A Scheduled Task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Create a directory path to the undelivered mail folder. ---> | |
<cfset undeliveredMailDirectory = "C:\ColdFusion8\Mail\Undelivr\" /> | |
<!--- Query for the undelivered mail items in this directory. ---> | |
<cfdirectory | |
name="mailStubs" | |
action="list" | |
directory="#undeliveredMailDirectory#" | |
sort="dateLastModified DESC" | |
/> | |
<!--- | |
Check to see how many undelivered files we have. If we | |
have more than the given threshhold, we need to alert the | |
server administrator that something has crapped-out in the | |
mail server. | |
---> | |
<cfif (mailStubs.recordCount gt 3)> | |
<!--- | |
Too many emails have failed! Something is breaking on | |
the server - might need a restart. Send email - of | |
course, since MAIL SERVER IS BROKEN, we cannot use the | |
configured mail server. Rather, we have to use a 3rd | |
party mail service; in this case, Google Mail (GMAIL). | |
---> | |
<cfmail | |
to="ben@bennadel.com" | |
from="coldfusion@bennadel.com" | |
subject="ColdFusion Mail Server Not Working (#mailStubs.recordCount# Undelivered Messages)" | |
type="html" | |
server="smtp.gmail.com" | |
username="****" | |
password="****" | |
port="465" | |
usessl="true"> | |
<h1> | |
ColdFusion Mail Server Has Probably Failed | |
</h1> | |
<p> | |
The following emails are sitting in the undelivered | |
mail folder on the server: | |
</p> | |
<ul> | |
<cfloop query="mailStubs"> | |
<li> | |
#mailStubs.name# - | |
#dateFormat( mailStubs.dateLastModified, "mm/dd/yyyy" )# | |
at | |
#timeFormat( mailStubs.dateLastModified, "hh:mm TT" )# | |
</li> | |
</cfloop> | |
</ul> | |
<p> | |
You might want to consider restarting the service. | |
</p> | |
</cfmail> | |
</cfif> | |
<!--- Mail sent! ---> | |
Done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment