I'm using cfmail tag to send out emails to the user. Additional thing I need to fulfill is to delete the records after sending them to the users. Is there any solution available to observe the cfmail task is whether completed or not. For example like a callback to indicate that the task was done.
With emails there are no guarantees that the email has been delivered.
If the cfmail tag executed without error there will be a record in the cfml spool directory. After the server hands the mail over to your SMTP server coldfusion removes the email from the spool directory.
NOTE: If your server is fast you will never see the mail in the spool folder.
You could try and build a solution that inspects the mail logs, but even that gives you no guarantee that the email has been delivered.
In most cases knowing that cfmail executed is enough.
<cfquery name="emailStuff">
SELECT * FROM mytable
</cfquery>
<cfloop query="emailStuff">
<cfmail>
cfmail contents/properties
</cfmail>
<cfquery>
DELETE FROM mytable WHERE ID=emailStuff.ID
</cfquery>
</cfloop>
Not sure if the above is what you're looking for. But this is a rough example of some code that will delete your DB entry after the mail has been sent.
Also cfmail has properties for failto and debug.
If an email fails it will send the failure email to whomever you specify in failto, or you can use debug to log failed emails.
see: cfmail docs
UPDATE: You could also move the delete query to outside the loop so that it only needs to delete from the database in one swift motion.
<cfloop query="emailStuff">
<cfmail>
cfmail contents/properties
</cfmail>
</cfloop>
<cfquery>
DELETE FROM mytable
WHERE ID IN (<cfqueryparam list="yes" value="#emailStuff.ID#" />)
</cfquery>
Related
I have:
Server Details
Server Product ColdFusion
Version 9,0,1,274733
Edition Standard
Operating System Windows Server 2008
OS Version 6.0
Adobe Driver Version 4.0 (Build 0005)
Is it possible that I can receive all the errors that happen on coldfusion to a specific email?
If you don't want to add a cferror to every page you can add a onError method to your application.cfc this function will be called whenever any page has an error.
<cffunction name="onError">
<!--- The onError method gets two arguments:
An exception structure, which is identical to a cfcatch variable.
The name of the Application.cfc method, if any, in which the error
happened. --->
<cfargument name="Except" required="true"/>
<cfargument type="String" name = "EventName" required="true"/>
error handling goes here
</cffunction>
I also saw you had a question where you were worried about the mail server not working. If you are worried that you will not be able to receive emails about your errors you can log them to a file.
<!--- Log all errors in an application-specific log file. --->
<cflog file="filename" type="error" text="Event Name: #Eventname#" >
<cflog file="filename" type="error" text="Message: #except.message#">
Check out the cferror tag. It is exactly what you need.
You can put cferror in the Application.cfm file, if you are not using Application.cfc, and it will work on every page.
<cferror type="exception"
template="/error.cfm"
mailto="your#email.com"
exception="any">
This is the recommended way to email notification of errors pre CFMX7. It still works in CFMX7 and after but best practice suggests the use the onError() method of Application.cfc
wikidocs.adobe.com/wiki/display/coldfusionen/onError
I'm working on a web app that is ran nightly to retrieve a large XML file from another server. We're using ColdFusion MX7. We run a CFHTTP GET with username, pass, and url. Then we write the field with a cffileaction write to our temp location. So that it can be parsed and sorted into a database. There are a few CFHTTP calls on the page cut one of them is failing. In the CFCatch I have the system email me the catch type and the message and I'm getting this.
COM.Allaire.ColdFusion.HTTPFailure
Connection Failure: Status code unavailable
This the call an write action as is (the credentials are right):
<cfhttp method="GET"
username="#uname#"
password="#pw#"
url="#url#"
resolveurl="yes"
throwonerror="yes">
</cfhttp>
<cffile action="write" file="#getdirectoryfrompath(GetCurrentTemplatePath())#\XML_FileName.xml" output="#cfhttp.fileContent#">
Is anyone familiar with his error?
As it turns out we were getting the Cert from the other groups 'test' server and then trying to using to get things from their production server. So Peter was right! If you run into this problem check out these links:
CFHTTP Over SSL
http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:48687
I have a coldfusion mail spooler locking up on me everytime I send out an email using this code:
<cfmail TO="xxxx#gmail.com"
FROM="xxxx#xxxxxx.com"
SUBJECT="Your Order!!!!!" type="html">
hello
</cfmail>
Only way I can get this thing to email out of the spooler is to stop IIS and start IIS.
Then it flushes through.
If I use
<cfmail TO="xxxx#gmail.com"
FROM="xxxx#xxxxxx.com"
SUBJECT="Your Order!!!!!" spoolEnable="false" type="html">
hello
</cfmail>
Then the email goes straight through no problem, I would like to use the spooler since it has a less lag for the user.
What's going on with my coldfusion spooler??
I am running 9,0,0,251028 (standard)
BTW: I have tried doing (with no luck):
<cfset sFactory = CreateObject("java","coldfusion.server.ServiceFactory")>
<cfset MailSpoolService = sFactory.mailSpoolService>
<cfset MailSpoolService.stop()>
<cfset MailSpoolService.start()>
This issue seems to be around since at least CF6.x and we haven't been able to find a permanent solution for it. Restarting the mail service is far from perfect.
Some have found that excluding the CF mail spooling directory from the virus scans helped, others say that sending emails with CFMAIL instead of with a cfscript did the job.
Here's a similar SO post and here's one from the Adobe forums
I have a ColdFusion template, which will be called via ajax.
The template has timeout of seconds like:
<cfsetting showdebugoutput="true" requesttimeout="2" />
But if the timeout occurs, I get no error message back. Is there a way to catch the timeout and respond properly via Ajax?
I get no error message back
Do you get anything back? Your response should still contain the text ColdFusion produces. Have you used Chrome, or fire bug or any browser with web tools that allow you to see the response to see if you're just getting back something you can't use? Are you using anything with a success/fail callback function that may be suppressing the failure on the client side? If the below suggestion doesn't help, I'd post your JS and re-tag your question.
That being said: any time you do anything after the request timeout has expired you'll want to extend your timeout. onError and try/catch only have a few MS after the timeout to react to the error so sending messages or logging errors will also fail. If you were trying to send an email or write to a file, you're CF error message would then say your cfmail or cffile action timed out which it did (technically) but it isn't what caused the initial error.
You can simply reset the requestTimeout to something a little bigger if you know what the timeout is already.
<cfsetting requesttimeout="2">
<cftry>
<!--- some stuff that takes more than 2 seconds --->
<cfcatch type = "any">
<cfsetting requesttimeout="5">
<!--- logging / error handling for timeout --->
<!--- NOTE!! This does not add 5 seconds, it adds 3. --->
<!--- The value of requestTimeout is the total time of the timeout. --->
</cfcatch>
</cftry>
Or you can add time if you don't know the current timeout value.
<cftry>
<!--- some stuff that takes more than your timeout --->
<cfcatch type = "any">
<!--- You must first create your object to hold the requestMonitor. --->
<cfset monitor = createObject("java", "coldfusion.runtime.RequestMonitor") />
<!--- Then you need to reset your request timeout --->
<!--- add 5 seconds to the timeout --->
<cfsetting requesttimeout=monitor.getRequestTimeout()+5>
<!--- logging / error handling for timeout --->
</cfcatch>
</cftry>
You do not have to do this in a try/catch block either, you can include this in your onError event handler if you have one defined in your application.cfc.
If the ColdFusion template is in a folder for which there is an Application.cfc file, you might be able to do something with the onError function.
You should wrap your entire ColdFusion template that is being called by AJAX in a cftry block. That way if any ColdFusion exception occurs you can handle it and return whatever message you want to the client.
<cftry>
<!--- all of your ColdFusion template code here --->
<cfcatch type="Any">
<!--- return whatever you want here --->
<div>An error has occurred.</div>
<!--- remember that you have the cfcatch structure available to you --->
<!--- which contains the specifics of the error that was thrown --->
</cfcatch>
</cftry>
On the client side, where the AJAX call is being made, you can handle any http connection related errors that might occur (failed connection, timeout, etc.). Your AJAX call will have an error method or some such. I highly recommend using jQuery for this. jQuery AJAX API
You did not give any specific information in your post. If you have a problem it always helpful to actually share the code you are having trouble with. Then the people on StackOverflow can be of more help.
We have a dedicated server running CentOS and Coldfusion 8.
All cfmail email is routed through Google with cfmail and smtp.
Every now and then, when cfmail is used, the 'FROM' field uses an address from a totally different website.
For instance:
Use form on Site A
Get an email: "Subject: On Site A From: siteb#siteb.com"
Where the from is a completely different variable in another set of code on another part of the server- there is no reason it should see this.
On the other side, sometimes sending an email to sitea#sitea.com has email wind up in Site B inbox, a completely different Google account.
What causes this to happen? Some kind of memory/cache issue? Or is there a funky DNS record causing issue?
Example:
Application.cfm (starts with some UDF includes, and then):
<cfinvoke component="#request.componentPath#.variables" method="getGlobal" />
Variables.cfc (a lot of variables defined within, but here is the cfmail vars):
<cffunction name="getGlobal" access="public" output="false" returntype="void">
<cfscript>
request.siteEmail = "email#mysite.com";
request.siteMailServer = "smtp.gmail.com";
request.siteMailUsername = "root#mysite.com";
request.siteMailPassword = "[redacted]";
</cfscript>
</cffunction>
It sounds like it's possible it could be a var scoping issue, but we can't know for sure until you share some code...
Looks like you're running multiple sites? there's a setting in the CF caching page in admin to do with caching web server paths:
From http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSc3ff6d0ea77859461172e0811cbf3638e6-7ffc.html :
Disabling the cacheRealPath attribute To ensure that ColdFusion always returns pages from the correct server, disable Cache Web Server Paths in the Caching page of the ColdFusion Administrator. (When you use the multiserver configuration, set the cacheRealPath attribute to false for the ProxyService in the jrun_root/servers/servername/SERVER-INF/jrun.xml file.)
Might not be it, but it's at least quick to try out.