Skip to main content
Gary__F
Inspiring
May 30, 2012
Question

Duplication of emails using cfmail

  • May 30, 2012
  • 3 replies
  • 13182 views

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.

This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
June 7, 2012

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.

Gary__F
Gary__FAuthor
Inspiring
June 7, 2012

I installed all hotfixes for 8.01 that addressed cfmail issues. CF Admin tells me there 2 are installed: hf801-00001 and chf8010004. I'm sure I installed more but maybe the little security fixes don't show up on the info page.

I've had several mail related issues over the years with CF; some were fixed using a workaround, others with a hotfix.

BKBK
Community Expert
Community Expert
June 7, 2012

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.

Inspiring
June 6, 2012

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

Gary__F
Gary__FAuthor
Inspiring
June 6, 2012

Hi Adam. I checked the processes and there's 1x jrun.exe and 1x jrunsvc.exe on each of the CF servers. That's useful info to know but it doesn't look like that's happened here from what I can see.

You've just given me a thought. We used to have problems with CF's MailSpoolService failing so I use a schedule script to check if we have aging unsent mail and if so restart the service. The code to restart is:

<cfset sFactory = CreateObject("java","coldfusion.server.ServiceFactory")>

<cfset MailSpoolService = sFactory.mailSpoolService>

<cfset MailSpoolService.stop()>

<cfscript>sleep(2000);</cfscript>

<cfset MailSpoolService.start()>

Is it possible that there are several mailspool services running if one recovered by itself after dying? As these are Java services and aren't shown in Windows Task Manager is there another way to check?

Inspiring
June 6, 2012

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

Gary__F
Gary__FAuthor
Inspiring
June 1, 2012

BUMP!

To help debug this I'm now generating a big random number at the top of my code and another random number within the cfmail tag itself. Both random numbers are inserted into the email message. If the page is called twice or cfmail is looped you'd expect to see the duplicate emails showing the same random numbers. This has not been the case. All numbers are totally unique. Therefore the page and cfmail is run once only.

Some emails have been sent in triplicate by the way! So something weird is happening outside of my code. CF is logging each duplicate in mailsent.log so it's not the SMTP server at fault.

The code is no more complicated than this after a form post.

<cfif IsDefined("form.email")>

<cfset emailTo="admin@mydomain.com">

<cfset randomID=RandRange(100,1000000,"SHA1PRNG")>

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

Dear Administrator,<br>

Blah blah...<br><br>

#form.message#<br>

<!--- insert randomID generated outside of cfmail, then insert a random number generated inside cfmail --->

Page ref: #randomID#. Mail ref: #RandRange(100,1000000,"SHA1PRNG")#

</cfmail>

</cfif>

Ignore the weirdly displayed email addresses, this forum keeps turning them into funny links.

BKBK
Community Expert
Community Expert
June 1, 2012

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>

Gary__F
Gary__FAuthor
Inspiring
June 1, 2012

I've simplified the code to just the cfmail tag and I still get duplicate emails. I just worked out that it only happens from one of our CF servers. Let's call it server 2. When the pages are served by server 1 then I don't get any duplicate emails. Clearly it's a server specific issue.

Both servers are behind a hardware load balancer using sticky sessions so a visitor will always stay with the same CF server. The servers are identical in terms of hardware, OS, CF version and configuration. The cfm files are on a DFS network share so both servers use the same files.

Why would one CF server send & log the same email several times, but it's twin sister does it once?