0

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.

Anurag
  • 1,018
  • 1
  • 14
  • 36
zawhtut
  • 8,335
  • 5
  • 52
  • 76

2 Answers2

1

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.

M.Scherzer
  • 921
  • 7
  • 9
1
<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>
TomDillinger
  • 194
  • 7