9 Replies Latest reply on Feb 21, 2008 3:47 AM by Prasanth Kumar.S

    Coldfusion emails

    TiGGi Level 1
      Hi all...

      I am looking for a better technique for sending emails via CF. What I've done so far is used <cfmail to generate emails. I used <cfloop to send email to all email addresses in the db since email content differ from user to user. Let me tell you right away that what we send is not SPAM in any way, these are valid email with info that users are asking for, so you're not contributing here to something bad!
      With that sad I am just looking around to see if there are any better ways of sending large number of emails.
      One thing that I've ran into when sending unverified email accounts is that if the email address is bad my process will error out and stop. Is there anyway to avoid this when sending?
      Also I was wondering about the process where you actually write cfmail files directly to spool folder of CF, is this practical, recomended?
      Give me your thoughts from your experience!
        • 1. Re: Coldfusion emails
          Dan Bracuk Level 5
          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.

          • 2. Re: Coldfusion emails
            reya276
            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
            FROM dbo.Newsletter_Reg
            ORDER BY reg_name ASC
            </cfquery>

            <cfmail query="emails" to="#reg_email#" from="optin@name.com" Subject="#form.subject#" replyto="optin@name.com" type="html" spoolenable="yes">
            <cfinclude template="newsletter_files/#sendnews.temp_name#.txt">
            </cfmail>

            this send out a newsletter to everyone in the emails table. No need for looping.
            • 3. Re: Coldfusion emails
              TiGGi Level 1
              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!
              • 4. Re: Coldfusion emails
                TiGGi Level 1
                Anyone?
                • 5. Re: Coldfusion emails
                  Dan Bracuk Level 5
                  How are you currently determining the content for each user? Is it something that can be generated from query results?
                  • 6. Re: Coldfusion emails
                    Level 1
                    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!
                    • 7. Re: Coldfusion emails
                      TiGGi Level 1
                      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.
                      • 8. Re: Coldfusion emails
                        Level 1
                        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...
                        • 9. Re: Coldfusion emails
                          Prasanth Kumar.S Level 1
                          Hi,
                          You can try the Asynchronous call in CF to send the emails so that the mails will be sent as a background process.

                          Prasanth