Link to home
Start Free TrialLog in
Avatar of Eric Bourland
Eric BourlandFlag for United States of America

asked on

Loop through UserEmail addresses to send a mass email -- 10 records at a time -- using CFMAIL / maxrows attribute?

My task: I need to send an email message to 914 people. These people's information is in a data table, NBPTS_Principals_Unapproved.

My strategy is, I will query the table NBPTS_Principals_Unapproved, loop through the 914 table rows (one row per person), and use CFMAIL to deliver an HTML formatted email message.

Each person will receive the email only one time. And, only ten email messages will go out in a single SMTP request.

Is it possible to do this using the MAXROWS attribute of the CFMAIL tag?

I did some reading on CFMAIL:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f8e.html

If I understand this documentation correctly, then MAXROWS will do what I want.

My questions:

1. Does anyone have any advice about sending bulk email messages using CFMAIL? I do not want my SMTP server to get flagged as a spam source.

2. Am I using CFLOOP and CFMAIL correctly, below?

Thank you as always for any advice. =)

Eric
<!-----
Name:        email_principals_template.cfm
Author:      Eric B

Description: This template does these actions:
1) query table NBPTS_Principals_Unapproved to get Names and Email addresses of 914 Principals who were not approved for the NBPTS Field Test
2) create an HTML formatted email message to send to each principal
3) 

Created:     September 2010
ColdFusion Version 8
MS SQL Server 2005
----->

 <!--- Set the datasource --->
 <cfset ds="ebwebwork">

 
  <!--- select columns from table tbl_NBPTS_Principals, for use later in this application --->
  <cfquery datasource="#ds#" name="GetPrincipalstoApprove">
  SELECT UserID
     , Salutation
     , FirstName
	 , LastName
     , Address
     , City
     , State
     , ZIP
     , UserEmail
  FROM NBPTS_Principals_Unapproved
  </cfquery>
  

<cfloop query="GetPrincipalstoApprove">

<!--- generate email --->
<!--- email message goes inside CFLOOP --->

<cfmail
      SERVER="mail.nbptsprincipals.org"
      FROM="NBPTS Principals Field Test"
      TO="#UserEmail#"
      SUBJECT="NBPTS Principals Field Test"
      username = "xxxxxxxx"
	  password = "xxxxxxxx"
      type="html"
      SpoolEnable="Yes"
      query="GetPrincipalstoApprove"      
      maxrows="10">
      

<!--- begin cfoutput --->
<cfoutput>

 <!--- begin formatted email message --->
<html>
<head>
<title>NBPTS Principal Field Test</title>
</head>

<body lang="EN-US">
      
      <div style="width:800px;padding:20px;text-align:left;">
      
  <img src="http://www.nbptsprincipals.org/img/nbpts_email_letterhead.gif" width="710" height="158" alt="NBPTS Letterhead" />

  <p>September 17, 2010</p>


<p>#GetPrincipalstoApprove.Salutation# #GetPrincipalstoApprove.FirstName# #GetPrincipalstoApprove.LastName#<br />
#GetPrincipalstoApprove.Address#<br />
#GetPrincipalstoApprove.City#, #GetPrincipalstoApprove.State# #GetPrincipalstoApprove.ZIP#</p>

<p>Dear #GetPrincipalstoApprove.Salutation# #GetPrincipalstoApprove.LastName#,</p>


<p>Thank you for expressing your interest in participating in the National Board for Professional Teaching Standards Principal Certification field test. We had an overwhelming response from principals across the country, hearing from nearly 2,000 principals who indicated a desire to take on this professional challenge.</p>

<p>We only selected 600 principals based on field test criteria. According to these criteria, you were not selected to participate in the field test. Selection to participate in the field test is not a designation of merit, but rather designed to assure validity and reliability of the assessment for principal in all school types.</p> 

</div>


</body>

</html>

</cfoutput>
<!--- close cfoutput --->
      
</cfmail>
<!--- close cfmail --->

</cfloop>
<!--- close cfloop --->

Open in new window

Avatar of Eric Bourland
Eric Bourland
Flag of United States of America image

ASKER

Hmmm. Should I put the CFMAIL inside the CFLOOP? Or the CFLOOP inside the CFMAIL? I am trying to think how that will work.
Avatar of Bhavesh Shah
Hi Eric,

How are you ?

Good to see you again :-)

cfmail is like cfoutput.

check out this link.

you can use query with cfmail tag directly

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_m-o_01.html

The best approach is you create the isSendMail field in your table, for every 10 emails, make their value to 1, then requery that query again after a schedule of every 3 hours [I assume you know cfschedule], then it will query again and fetch another batch of records and send again. after agaion 3 hrs of Gap, it will do it again..

This way you can make the work easy..

or check this

http://tutorial256.easycfm.com/

Sory Mr.Eric,

I didnt read your Q properly.

Very Sory
Brichsoft and myselfrandhawa, thank you for these comments. myselfrandhawa, I will try the isSendMail column and the cfschedule idea -- that is a good idea.

Do you think that I need the CFMAIL tag inside the CFLOOP tag? Or should I put the CFLOOP inside the CFMAIL?

Thank you again. Hope you are both doing very well.

Eric
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Very good points by gdemaria.  Before you decide on a table structure, it's good to think ahead ... consider what types of emails you might be sending in the future.  Then design accordingly (ie for flexibility).
make sure you also consider bounced back emails in that
myselfrandhawa, this tutorial:

http://tutorial256.easycfm.com/

is very helpful and I have read it. The notes at http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_m-o_01.html about CFMAIL, I have reviewed carefully.

gdemaria, I agree that it is better to set up this application with the future in mind. And this client will need to send this email several times to the group of people in this database table. The client is in a terrible hurry, and rushing me, so for now I will set up just this simple page and send the email. Later I will set up the child table as you suggest -- that is a good idea.

I am reviewing the notes on CFSCHEDULE here: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c6e.html

@ _agx_ your idea looks very good and I am going to try that. You and myselfrandhawa say to use CFSCHEDULE ... does that mean, include the CFSCHEDULE tag inside my template email_principals_template.cfm ? Or does CFSCHEDULE go inside its own template? I am just not sure how this will exactly work.

Thank you as always for helping me figure this out. Hope you all are doing well.

Eric
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@gdemaria

>>So, I suggest just doing it in admin to get it done quickly and easily.

Good idea.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gdemaria,

Thanks for all of this. I am working on this code. I need to run out to a meeting and will be back at my desk later this evening to resume work.

To answer your question, a new user record added to the table should not receive an email 15 minutes after the user record is created.

I am going to add the emailReminderDate column. I will be able to focus on this task later on.

Thank you again.

Angsty client = angsty Bourland.

Eric
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think this is working. I will test more tomorrow.

=)

Good evening to all.

Eric
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good morning friends. This application is working like a charm and I am following up with the client to straighten a few more details. The use of the emailReminderDate column is a great idea. I see how that works -- it is elegant. It was easy to set up a schedule for this task in Cfadminstrator. I will come back later today to close this question but in the meantime I wanted to say, Thank you as always. I hope your Friday is going well.

Eric
>> The use of the emailReminderDate column is a great idea...-- it is elegant

Yep.  gdemaria's has a talent for the deceptively simple approaches :)  Powerful and elegant is a great combination.

Thanks agx, a nice complement, particularly coming from an expert whose comments are so well respected by myself and the ee community
Aw, thanks .. and you're welcome. But after seeing much of the good advice you've provided over the years at EE, it's just a statement of fact :)
One note that I saw in the documentation. The CFMAIL FROM attribute can be a plain text string:

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_m-o_01.html

"E-mail message sender:
* A static string; for example, "support@mex.com"
* A variable; for example, "#GetUser.EMailAddress#".

This attribute does not have to be a valid Internet address; it can be any text string."

So I think the FROM attribute, below, is valid:

and the tests I did last night seem to be OK with a text string as a value for the FROM attribute. It was interesting to learn this b/c I always thought the FROM attribute needed a valid email address, as gdemaria noted above.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>>="NBPTS Principal Certification Field Test <admin@nbptsprincipals.org>"

I think you are right.

 Also, I believe your emails would be caught up in many spam filters without a valid From email address.

 By valid email, I mean an actual mailbox.  You can create an unmonitored mailbox such as  noReply@...

 You don't need to use anyone's "real" mailbox..
>>Also, I believe your emails would be caught up in many spam filters without a valid From email address.

That is true!

I used a valid email address. Per the client's request.

I am also using DKIM / Domain Keys signing, and valid SPF and RDNS values, to maximize delivery success.

I uploaded the template and set the schedule in CF Admin. Emails are scheduled to start sending at 3 p.m. US CST. I have reviewed the code until I am blue in the face. Yes, I am on tenterhooks.

=)
>> Yes, I am on tenterhooks.

You could always email yourself too. ie Add your address as a BCC.  Just so you can know what's happening.  I do that sometimes when I'm really nervous.  Just temporarily of course ...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@gdemaria,

<cfif len(attributes.testEmail)>  
     <div style="color:red;">Email to: #GetPrincipalstoApprove.UserEmail#</div>  
   </cfif>


That is a good idea. The application is already working ... the client really wanted me to push this live before COB Friday (today). But I have incorporated this code into my application. Next time the client wants me to send a bulk email message using this application, this testEmail method will make me less of a nervous wreck before I launch the application.


>>>Just a reminder Eric...  any new record added to that user table will have an EMPTY value in the column: emailReminderDate.
>>>That makes the new user eligible to receive email if the scheduled task is still running.

I understand that 100% and I will monitor that. After this application does its work, I will do:

alter table NBPTS_Principals_Unapproved  add emailReminderDate default '1/1/1900'

I am also working on that child table you mentioned. Might as well make this a flexible application that will be useful multiple times.

This has been incredibly instructive and helpul.

Eric B
Hmmm. I thought I accepted multiple solutions for this question, from gdemaria, _agx_, and myselfrandhawa. I did not want to simply close this question. Moderator, will you please look into this matter? I want to express gratitude to gdemaria, _agx_, myselfrandhawa, and Brichsoft. The application is working perfectly thanks to them.

EricBourland

Thanks eric for objecting :-)

I really dont know,many authors closing the QUESTION with accepting the solutions.They just giving the points.
I have tried twice to accept solutions, above, and award points for this question. The question is still open and I do not have confirmation that the experts have received their points. I have followed up with Experts Exchange and hope to resolve this matter soon. Thanks for your patience.

Eric B