testing a mailserver

ColdFusion Add comments

It would be nice to check whether a mail server is able to accept connections before you try and use the CFMAIL tag. Previously, the CF administrator was the only place you could verify a connection - but leverage the factory java objects and you can do it really neatly. I was looking for an answer as to how to do this for a thread in the MM forums and found this neat little UDF so i thought i’d share it here. Remember, it’s using factory methods so these might not be supported in subsequent releases of CF.

<cfobject action=“CREATE” type=“JAVA” class=“coldfusion.server.ServiceFactory” name=“factory”>
<cfscript>
function my_cfusion_verifymail(smtp,port,timeout)
{
ms = factory.getMailSpoolService();
ms.setServer(smtp);
ms.setPort(val(port));
ms.setTimeout(val(timeout));

if (ms.verifyServer()) return “”;
else return “Error”;
}
</cfscript>

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in