Just a word of advice...  Use a group by clause instead of distinct; just
copy all of the fields in the select part and remove all aliases and you
have a statement that retrieves distinct records, and performs way better.
Your statement would look like:

        SELECT email
        FROM users
                GROUP BY email



-----Original Message-----
From: Bryan Love [mailto:[EMAIL PROTECTED]] 
Sent: Monday, July 16, 2001 10:54 AM
To: CF-Talk
Subject: RE: Duplicate e-mails generated by CFMAIL?


use DISTINCT in your email select to ensure that duplicate email addresses
are not being retrieved:

SELECT DISTINCT email
FROM....

Also, you can use the email query in the CFMAIL tag like so:


                <cfmail query="email_address"
                        to="#email_address.email#"
                        from="[EMAIL PROTECTED]>"
                        subject="Daily News"
                        server="home.com"
                        port="25"
                type="HTML">


and this will cause the CFMAIL tag to loop over the results of the
email-address query.  It's faster to use it this way since multiple
instances of the CFMAIL tag aren't called inside the CFLOOP.

If you are still sending doubles after this then you can rule out Cold
Fusion and start looking at your mail server.  Also, you can access the mail
logs through the CF administrator for more detailed info about what happened
                                                    
Bryan Love ACP
Internet Application Developer
[EMAIL PROTECTED]
                                                    


-----Original Message-----
From: David Grabbe [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 16, 2001 9:21 AM
To: CF-Talk
Subject: Duplicate e-mails generated by CFMAIL?


Hello all,

I am in the process of putting together an e-mail newsletter (using CFMAIL),
and everything is working fine except that each email address is receiving
TWO emails instead of one.  Obviously this is not going to make for happy
recipients  :)  Can anybody see (from the code below) why I am generating
duplicate emails?


Cheers,
David

---------------------------------------------------------------------

<cfset TestDate = CreateODBCDate(Now())>
<cfset yesterday = '#DateAdd("d",-1,"#TestDate#")#'>


<cfquery name="email_address" datasource="dsn"
cachedwithin="#CreateTimeSpan(0,23,0,0)#">
        SELECT email
        FROM users
</cfquery>



<cfquery name="articles" datasource="dsn"
cachedwithin="#CreateTimeSpan(0,23,0,0)#">
        SELECT *
        FROM world_news
        WHERE date_entered >= #yesterday#
        AND date_entered < #TestDate#
        ORDER BY news_date DESC
</cfquery>

<cfif articles.RecordCount GT 0>


        <cfloop query="email_address">

                <cfmail to="#email_address.email#"
                        from="[EMAIL PROTECTED]>"
                        subject="Daily News"
                        server="home.com"
                        port="25"
                type="HTML">

                        <!---

                        beginning of email content here

                        --->

                        <cfloop query="articles">

                        <!---
                        Looping through the news articles...
                        --->

                        </cfloop>

                </cfmail>

        </cfloop>

</cfif>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to