Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using CFMail to send to 1 but BCC to many

Status
Not open for further replies.

mike2277

Programmer
Mar 25, 2002
54
US
Hi,
Hoping this is an easy one where I'm just overlooking something.

I am using Windows Server 2000, CF MX 6.1 and SQL Server 2000.

I have recently create a form for myself where I can send an email to many of my colleagues. Originally I was putting everyone's email address in the TO field but a few people complained and asked that maybe I try to put everyone in the BCC field so they don't have to scroll down through a large list of people I sent to in order to begin reading the message.

So now I just put my own email address in the TO and FROM fields and all of the recipients email addresses in the BCC. The query loops through all of the users in the database who have email addresses and sends it correctly.

My only problem though is that if I send the email to my 220 users then I also get 220 emails.

QUESTION: Is there a strategy I can use to just send to myself (TO field) just once while also sending to the 220 users in the BCC field?

Here's my code:

<CFMAIL
SERVER=&quot;112.223.24.22&quot;
QUERY=&quot;com&quot;
PORT=&quot;25&quot;
TIMEOUT=&quot;60&quot;
SUBJECT=&quot;#FORM.TITLE#&quot;
TO=&quot;admin@example.org&quot;
FROM=&quot;admin@example.org&quot;
BCC=&quot;&quot;&quot;#FirstName# #LastName#&quot;&quot; <#Email#>&quot;>

Thanks in advance!

Mike
 
You could create a list and put all of the email addresses in it, then just use the list in your BCC field of your cfmail tag.

Hope This Helps!

Ecobb
- I hate computers!
 
Thanks so much for the advice. It's a relief knowing that there is a strategy for accomplishing this. Unfortunately I have no clue on how to code a list in the BCC field.

I found some example list code on the Net and I'm wondering if this is what you mean?

--------- start code example ------------

<cfquery name=&quot;users&quot;>
SELECT Distinct email FROM database WHERE subscribed = 1
</cfquery>

<cfset counter = 1>
<cfset userList = &quot;&quot;>
<cfloop query=&quot;users&quot;>
<cfif counter eq 30>
<cfmail from=&quot;webmaster@d...&quot; bcc=&quot;#userList#&quot;
subject=&quot;list email&quot;>
Your mail message data here
</cfmail>
<cfset userList = &quot;&quot;>
<cfset counter = 1>
<cfelse>
<cfset userList = listAppend(userList, users.email. &quot;;&quot;)>
<cfset counter = counter + 1>
</cfif>
</cfloop>
<cfif len(trim(userlist))>
<cfmail from=&quot;webmaster@d...&quot; bcc=&quot;#userList#&quot; subject=&quot;list
email&quot;>
Your mail message data here
</cfmail>
</cfif>

------------ end code example -----------

I didn't comment the code above, but I think it is fairly obvious.
Get the emails
setup a counter variable and a list for email addresses
loop over the result
increment your counter
add the users to a list
when the counter gets to a predefined point (30 here) send the email to
the users on the list, empty the list, reset the variable and continue
looping through the results
at the end, send the email to any of the remaining users who it was not
sent to in the loop.
 
You may can simplify it and try something like this:

<cfquery name=&quot;users&quot;>
SELECT Distinct email FROM database WHERE subscribed = 1
</cfquery

<cfset userList = ValueList(users.email,&quot;;&quot;)>

<cfmail from=&quot;webmaster@d...&quot; bcc=&quot;#userList#&quot;
subject=&quot;list email&quot;>
Your mail message data here
</cfmail>

This should get you started. In the cfset statement, use the Valulist function to create a single list with all of the values returned from your query. I specified a &quot;;&quot; as the list delimiter since cfmail will need the semicolon to seperate each email address. When you run your cfmail tag, just specify the list variable you created in the cfset statement for the BCC field. The output of the list should be something like: &quot;email1@whatever.com; email2@whatever.com; etc...&quot; Now cfmail will only execute 1 time, and you will only get 1 email.

However, if I'm not mistaken, cfmail has a limit on the number of email addresses it will allow in the cc and bcc fields. I think that limit is somewhere around 40, I know I have another thread in this forum where I found the exact number. I'll see if I can find that thread and post the link here.

Hope This Helps!

Ecobb
- I hate computers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top