Skip navigation
Currently Being Moderated

Duplication of emails using cfmail

May 30, 2012 5:12 AM

Tags: #email #duplicate #cfmail #duplication

Hi. I'm having a problem with cfmail sending out the same email twice. The mailsent.log shows the same emails sent again at exactly the same time to the very second. It's not caused by double-clicking the submit button, it happens with a single click. There are no loops in my code, not even a query or a cfc. It only happens on our prd servers, not our dev server. The main differences is prd uses a multi-instance installation and dev does not, plus dev doesn't have all the hotfixes that prd has.

 

What could cause CF to send the same email twice within the same second? Someone reported this 4 years ago in this thread but there was no resolution!

 

Setup: CF8.01 Ent with hotfixes, Win2008 R2, IIS7.5, Microsoft SMTP server.

 

Thanks in advance.

 
Replies
  • Currently Being Moderated
    Jun 1, 2012 5:50 AM   in reply to Gary__F

    Strip the code down to its most basic, such as below. Does the issue persist?

     

    <cfif IsDefined("form.email")>

    <cfmail to="admin@mydomain.com" from="server@mydomain.com" replyto="#form.email#" subject="Test message" type="html" failto="failedmail@mydomain.com" mailerid="My Special Mailer">

    test mail

    </cfmail>

    </cfif>

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 2, 2012 1:11 AM   in reply to Gary__F

    Strange. Are you using any form of session replication? Is it possible 2 or more session threads open the action page?

     

    Run the following test. Do you get duplicate log entries? What test values appear in the logs? (I have assumed the form page and action page are not the same. If they are, use <cfparam> instead.)

     

    On the form page:

    <cfset session.mailTest = 0>

     

    On action page:

    <cfif IsDefined("form.email")>

    <cfset session.mailtest=session.mailTest+1>

    <cflog text="mail test: #session.mailTest#" file="mailTest">

    </cfif>

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2012 12:13 AM   in reply to Gary__F

    Could we have a look at the form page?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 4, 2012 8:54 AM   in reply to Gary__F

    Just bear with me. What is the result when you use the following, even more basic, code?

     

    <cfif IsDefined("form.email")>

        <cfmail to="test@mydomain.com" from="noreply@mydomain.com" subject="dupe email test">

        Test email.

        </cfmail>

    <cfelse>

        <cfoutput><FORM name="form2" id="form2" action="#cgi.script_name#"></cfoutput>

        <INPUT name="email" type="text" id="email" size="30">

        <INPUT name="submitBttn" id="submitBttn" type="submit" value="Submit">    

        </FORM>

    </cfif>

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 5, 2012 12:58 AM   in reply to Gary__F

    On reading up on the issue, I found that the possible causes could be:

     

    1) Page being requested twice. We have ruled that out(cflog ran once only, session counter not incremented). To be sure, we had to rule out double-clicking, too. Let's do that now.

     

    Does the following code (just a CFM page, no form submission) send duplicate e-mails?

     

    <cfmail to="test@mydomain.com" from="noreply@mydomain.com" subject="dupe email test">

        Look, no submit button!

        </cfmail>

     

    2) Type="HTML", possibly together with form post from Internet Explorer. We have ruled out e-mail type. Not yet the browser type. Does issue occur with Firefox?

     

    3) Mail server. Open the source file of each e-mail in a set of duplicates. Read off the message IDs. If they are the same, then the mail server is likely causing the issue. If they are distinct, the ColdFusion server is likely causing the problem, as it must have instructed the mail server multiple times to send an e-mail.

     

    4) When a similar issue was discovered in Railo last year, the following workaround seemed to help: spoolenable="no". Hence, I would test with

     

    <cfmail to="test@mydomain.com" from="noreply@mydomain.com" subject="dupe email test" spoolenable="no">

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 4:50 AM   in reply to Gary__F

    It sounds to me like you've got an additional (orphaned) jrun process running on that server.  Sometimes if a CF instance seems to crash, JRun will start it up again, however the original one sometimes also recovers, leaving two CF instances servicing each request.

     

    How many JRun processes have you got running?

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 5:39 AM   in reply to Gary__F

    I have never had any luck with that tactic... all I ever ended up with is multiple mail spool services running...

     

     

    That said, this does not really explain the situation you mentioned wherein each mail message had its own unique random number.  CF deals with the random number side of things, the mail spooler just processes the mail.  So if you had one CF process and multiple mail processes, you'd get multiple mail messages with the same CF-generated random number (if that makes sense).

     

    It definitely looks like CF is processing those templates more than once.

     

    Dunno what further to suggest at the moment, but I'm giving it some thought.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 6:14 AM   in reply to Gary__F

    Ah right.  OK, that points to perhaps multiple mail spooler processes runing, perhaps caused by (or at least not helped by ~) your code above.

     

    Can you get rid of that code, and just restart the CF server that's causing the problem?

     

    I'm guessing (and it's just a guess) that the mail spooler runs as some sort of daemon within the JVM, so restarting CF should get rid.

     

    It sounds like you've got more than one prod box, so this should be OK to test at some stage, shouldn't it?

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 11:51 PM   in reply to Gary__F

    Gary__F wrote:

     

    I rebooted server 2, disabled the script that stops/starts the mailspoolservice and got it to send a few emails without the spoolenable="no" setting. So far I've not seen any duplicate emails.

     

    If we've identified the cause of the problem by disabling my schedule script then I need to find a better way of detecting a dead mailspoolservice and restarting it. I played around with the servicefactory and there are no functions that disclose how many instances are running or if there are no instances running.

    In view of the recent developments, my take on it now is that the cause was a fault in the spooling mechanism. It resulted in each e-mail being spooled twice or more.

     

    I think the server restart (essentially a reset) is a sufficient solution. I would further do nothing with the Mailspoolservice.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 12:37 AM   in reply to Gary__F

    I need to find a better way of detecting a dead mailspoolservice and restarting it. I played around with the servicefactory and there are no functions that disclose how many instances are running or if there are no instances running.

     

    I wonder if it's possible to set up a second CF instance that simply handles the mail spooling?

     

    Looking @ neo-mail.xml, one could perhaps set the number of mail threads on your prod box to be zero (one cannot set it to zero via the CFAdmin UI), and then on the second instance point its spool dir to be your prod instance's mail dir.  This might cause the prod instance to still write the files to the spool dir, but not try to send them (this is predicated on the spool threads also not having a hand in getting the files to the dir in the first place, I guess), and the second instance will send 'em.  And if the second instance stops working, then it's low-impact to restart it.

     

    Is that an option?

     

    And, hey: I dunno if that'll work, and I don't have the resources here to test it, sorry.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 3:55 AM   in reply to Gary__F

    Gary__F wrote:

     

    Setup: CF8.01 Ent with hotfixes ...

    On an entirely different note now, which hotfixes did you install (on server 2 in particular)? There were some hotfixes for CF8.0.1 to fix cfmail issues.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 12:24 PM   in reply to Gary__F

    Gary__F wrote:

     

    I installed all hotfixes for 8.01 that addressed cfmail issues. CF Admin tells me there 2 are installed: hf801-00001 and chf8010004.

    I spotted a problem. ColdFusion hotfixes of these types are cumulative. I do believe that you had to delete the JAR file for hotfix 1 before installing hotfix 4. See Step 6 of the CF8.0.1 hotfix 4 installation notes. In any case, I suppose it is all right to stop ColdFusion, reverse both hotfix 1and hotfix 4 installations, and then reinstall hotfix 4.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2012 12:03 AM   in reply to Gary__F

    Look at the last digit, the hotfix number. You are talking about 4 and 4. I was actually talking about the presence of 1 and 4 on the same server.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2012 5:11 AM   in reply to Gary__F

    This is important. Why not ask Adobe whether the JARs hf801-00001 and chf8010004 should be installed simultaneously.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2012 5:59 AM   in reply to Gary__F

    OK. Let's research it ourselves and save the $ for beer.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points