5

I have 2 clients on the same server that I host, that both send email through sendgrid.com (both have their own accounts).

I was looking at reports on sendgrid and noticed that categories from "client 1" were showing up in a report for "client 2".

I spent extensive time on the phone with sendgrid and they are telling me that a handful of emails 65 from a batch of 3000 for "client 1" show as being sent through "client 2"'s authenticated user.

In my scripting, I use coldfusion cfmail and I specify the SMTP address, username and password for that client into the tag.

A possible theory takes into account the "Maintain connection to mail server" check box under mail in the administrator.

"Select this check box to keep the connection to a mail server open for reuse after delivering a message (recommended)."

If both clients send email at the same time (very much possible) would the coldfusion mail spooling engine separate them out based on server/username and password or send them all through to the mail server that is currently open?

If I uncheck the maintain connection to mail server checkbox... what is the downside on resources? my clients send newsletters and transactional emails all day, maybe about 10k each client.

steve
  • 1,490
  • 10
  • 18
  • I may have a work around to try. If I create a cname alias in one of my domains for sendgrid.mydomain.com and change my server address in my code, I am hoping coldfusion thinks its a different server and opens a separate connection for that domain so the mail doesnt get mixed up. – steve Nov 20 '12 at 21:24

2 Answers2

4

I don't know what version of ColdFusion you are running but in ColdFusion 9 a new feature was added that allows you to specify the SMTP server settings in your Application.cfc file. Assuming that you have separate Application.cfc files for your 2 sites then perhaps this will work for you.

Here is a reference to the new feature in ColdFusion 9

Here is the text from that referenced page.

Problem
How can I use the different SMTP Server Settings for Applications hosted in ColdFusion server for sending Email.

Solution
By using the new ColdFusion 9 “smtpServersettings" feature in Application.cfc file, we can specify different SMTP server settings for Applications.

Detailed explanation
ColdFusion 9 added a new attribute called "smtpServersettings" to the Application.cfc file. We can specify the SMTP server setting details to "smtpServersettings" attribute of THIS scope in Application.cfc which takes three values and they are server, username and password as a structure.

<cfcomponent displayname="CF9ApplicationVariables" output="false">

   <cfset this.name   = "CF9ApplicationVariables" />
   <cfset this.smtpserversettings   = {
                          server="mailServerAddress",
                          username="userEamilID",
                          password="userPassword"
                          } />
</cfcomponent>

Now the CFMail tag will use the server details for sending mails as mentioned above in "smtpServersetting" in Application.cfc and it won't use the server values specified in the ColdFusion 9 Administrator. If "smtpServersetting" attribute is not used then CFMail will behave as normally.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • Thanks, I'm running CF9, and wasn't aware of this. Most of the time I use the default mail server in administrator, my local SMTP server, but in this case I have 2 different sites that use a remote SMTP server (which happens to be the same server, but with different usernames and passwords). It seems that when coldfusion keeps the connection open for that server, it doesnt check to see if the authentication information has changed and keeps using the same login session because its the same server URL. – steve Nov 21 '12 at 13:59
  • For what it's worth I am running CF9 and was not aware of this either. Seems like it might be worth a try though. If you do try it please post back your results. As this only allows you to specify the server, username and password I'm not sure how the maintain connections setting (or any of the other admin settings) will come into play. – Miguel-F Nov 21 '12 at 14:04
  • When you use cfmail against a query, coldfusion generates a bunch of outgoing messages and puts it into the spool folder. the coldfusion mail spooler then picks up each message and examines it. If there is no special mail server defined, it delivers it through the default mail server. If you specify an alternate mail server, it creates a connection to it. Instead of logging in 1 time for each message, if you keep the "maintain connection" check box in administrator, it will send multiple messages through the connection. However, in my case, I use 1 server with multiple usernames and... – steve Nov 21 '12 at 14:54
  • passwords. Instead of recognizing that the username and password is not the same one that it authenticated with, it just ignores the username and password and keeps sending. I have 2 different clients that that I host on my server that use sendgrid, and during normal working hours, its entirely possible they send out email at the same time in batches, and the 2 sessions get cross. I appreciate your feedback. The DNS solution I found below is a definate work around the "bug" I think I found in CF 9. – steve Nov 21 '12 at 14:58
2

I ended up modifying the DNS settings in my servers, adding a cname that pointed to the smtp address, smtp.sendgrid.net. I then updated my code to use the new server names, and this seems to be separating the connections.

steve
  • 1,490
  • 10
  • 18