This content has been marked as final. Show 9 replies
Cold Fusion has a validate function which checks the email format. The best time to use it is before you store the address in your db.
why are you looping through it the CFmail tag has a query element which you can use.
Quick example of how we use it:
<cfquery name="emails" datasource="mssqlcf_name">
SELECT regID, reg_name, reg_email
ORDER BY reg_name ASC
<cfmail query="emails" to="#reg_email#" from="firstname.lastname@example.org" Subject="#form.subject#" replyto="email@example.com" type="html" spoolenable="yes">
this send out a newsletter to everyone in the emails table. No need for looping.
I guess cuz each user gets different email content! So do you think it would be better to create email body text file for each user and then sending it your way? Just keep in mind we're talking about thousands of email everyday, on some days over 100K!
Thank you for your help!
How are you currently determining the content for each user? Is it something that can be generated from query results?
Could you also put a CFTRY around the CFMAIL tag to catch the error if the email is not valid? If it got caught, you could flag that record as invalid so you don't have to try it again next time you email is sent.
Dan's suggestion of validating the email before storing is a good. I've also validated it just before I send the mail in the cases where I don't control the data entry. This validation would be done instead of the CFTRY.
As far as how to generate the mail message on the fly, I'm with Dan in trying to get the info you need based on a query. If the info is in the query results, you can just drop it in. Maybe you can store the email text in the database. I've also used include files in the past for generating the body of the email...
Hope that helps!
Hey guys thanks allot for your help!
Each user has their own settings so depending on those I generate email from the dB. I guess validating email is not my biggest concern since I do have some validations in place, I was looking more for "best practices" when comes to sending out large number of emails.
I don't know if it is a best practice, but one thing that I do for a similar tool I've created is send the emails out in smaller batches.
I have a queue DB table that stores emails to be sent. I then have a CF Scheduled task that runs every 15 minutes. It takes the next X number of emails and sends them, then removes them from the send queue and enters them in the sent table. This way, we didn't overtax our email server with giant blasts of thousands of emails all at once...
Again, not sure about best practicies, but our IT guys was much happier when we didn't bombard his email server with thousands of messages at once.
However, it does mean that the messages take longer to go out...
You can try the Asynchronous call in CF to send the emails so that the mails will be sent as a background process.