Output query results in a simple list, delimited by commas?

CF 9.0.1
SQL Server 2005

Hi again.

I need to use CFMAIL to send a message to a list of email addresses contained in a data table.

So, I query to get the email addresses:
  <!--- request test email addresses --->
  <cfquery datasource="#APPLICATION.dataSource#" name="GetAddresses">
  SELECT EmailID
       , EmailAddress
  FROM buddhaTestEmailAddresses
  </cfquery>
  

Open in new window

 
Next I set up CFMAIL:
<!--- generate email --->
<CFMAIL
      SERVER="server.buddhabyoga.com"
      FROM="#REQUEST.MailingListAdminEmailAddress#"
      TO="#GetAddresses.EmailAddress#"
      SUBJECT="#GetNewsletterContent.subject#"
      username = "someone@buddhabyoga.com"
	  password = "0000000"
      SpoolEnable="No"
      type="html">
      
      ... email content
      
      </CFMAIL>

Open in new window


My problem is the TO attribute. How can I output TO="#GetAddresses.EmailAddress#" as

TO="emailaddress1, emailaddress2, emailaddress3, emailaddress4"

I should be able to arrive at this solution based on solutions given to me previously, but I am having trouble. =) Thank you for your help.

Eric
LVL 3
Eric BourlandAsked:
Who is Participating?
 
gdemariaConnect With a Mentor Commented:

Depending on the relationship between each record of your query "GetAddresses" and the number of records expected, you either way to LOOP the CFMAIL or you can use valueList() to get a list in the TO line.

<cfloop query="getAddresses"
    <cfmail to="#getAddresses.emailAddress#"
               ...

this seems to be the preferred approach.

Unless you are getting a small number of emails that are from the same account (his email, her email, work /home email type of thing).   In that case, you don't mind having the person see all the email addresses in the TO line and there aren't too many of them.

Then you can do ...

<cfmail to="#valueList(getAddresses.emailAddress)#"

0
 
Eric BourlandAuthor Commented:
valueList was exactly the function I needed. I knew there was a function in there, and I was looking back through old code and old questions to find it. Thanks as always, gdemaria. I hope your weekend is going well. Eric
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.