Reputation: 478
Current scenario: Using cfmail tag with query for example.
<cfmail
query="qName"
to="#tomailvar#"
from="#frommailvar#>"
subject="#subjectvar#"
type="html"
server="smtp.sendgrid.net"
timeout="360"
username="#myuservar#"
password="#mypwdvar#"
>
how can i do threading in cfmail tag or current code?
I have client they send almost 40k in one shoot some time more. I gave multiple accounts to my client, some time they simultaneous two users or three users sends 40k + 40k+ emails.
Is there a way i can count messages in spooler folder and verify with my total count of query ?
what is the right way to handle this much emails?
Upvotes: 2
Views: 488
Reputation: 4475
Which version of ColdFusion are you using? I'm surprised that you aren't encountering timeout issues. Since ColdFusion 6, we've been saving the HTML, TEXT and email list to a separate database and then have a background task loop over the data and send it in smaller batches.
Have you considered using a Transactional Email Service? We recently switched from Mandrill (because they're rolling it into MailChimp) to SparkPost (Free tier = 100,000 messages/mo). This type of service would provide you with the best stats & bounce/read/click detection (and sending 40k messages would take about ~2 seconds using CFHTTP.) You could also incorporate using "tags" for your accounts that are sending so you can keep track or set up separate accounts for each client. (NOTE: If you use SMTP API, be sure to set up unique DNS CNAMES for each SMTP customer or ColdFusion may use an existing authenticated connection and send messages using the wrong SMTP account.)
In addition to SMTP connections (one message at time), REST APIs are available which allow you to generate & post a single JSON packet containing the HTML/TEXT templates, email list, substitution parameters, campaign id, tags, optional headers, etc. I prefer sending through these services because it doesn't result in my IPs being blacklisted or incur delivery delays of time-sensitive messages.
Here's a comparison chart of various transactional email providers.
http://socialcompare.com/en/comparison/transactional-emailing-providers-mailjet-sendgrid-critsend
Here's a sample REST API call using SparkPost. (I'm providing this because almost no third-party services provide code samples for CFML.)
<cfscript>
APIKey = "abc123";
/* Generate Message Object */
messageObject = {
"campaign_id" = "Test1234",
"options" = {
"open_tracking" = Javacast("boolean", true),
"click_tracking" = Javacast("boolean", true)
},
"recipients" = [
{"address" = {"email" = "[email protected]", "name"="User 1 Name"}, "substitution_data"= {"fullname"="Mr. User 1"}},
{"address" = {"email" = "[email protected]", "name"="User 2 Name"}, "substitution_data"= {"fullname"="Ms. User 2"}},
],
"content" = {
"tags" = ["testing", "demo"],
"from" = {"email"="[email protected]", "name"="My Name"},
"subject" = "Oh hey {{fullname}} (#Request.DateTimeFormat(StartTime,'m/d/yyyy')#)",
"html" = "<b>Testing REST API {{fullname}}</b><br><br>Sending email using a transactional email service.",
"text" = "Testing REST API {{fullname}} - Sending email using a transactional email service.",
"headers" = {
"X-CUSTOM-HEADER" = "foo bar"
}
}
};
/* Recommend using JSONUtil for proper casting of boolean values */
JSONUtil = CreateObject("component","JSONUtil");
MessageJSON = JSONUtil.Serialize(var=messageObject, strictMapping=true);
</cfscript>
<cfhttp url="https://api.sparkpost.com/api/v1/transmission" method="post" result="httpResp" timeout="60" getasbinary="never">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfhttpparam type="header" name="Authorization" value="#APIKey#">
<cfhttpparam type="body" value="#MessageJSON#">
</cfhttp>
<CFDUMP VAR="#httpResp#">
Upvotes: 4