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">
       , EmailAddress
  FROM buddhaTestEmailAddresses

Open in new window

Next I set up CFMAIL:
<!--- generate email --->
      username = "someone@buddhabyoga.com"
	  password = "0000000"
      ... email content

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 BourlandAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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)#"


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.