Send email from multiple servers evenly by looping over query

Posted on 2011-05-06
Last Modified: 2012-05-11
I'm looping over a query to send emails to my users.  I have 7 different email servers I want to send from and trying to figure out a way to break up the messages evenly across the servers.  

I was previously sending from 2 and using the following:

<cfoutput query="emailAlerts">

<cfif emailAlerts.currentrow MOD 2 is 0>
<cfset servername="">
<cfset username = "un"> etc etc


<cfset servername="">
<cfset username = "un22"> etc etc


<cfmail server="#servername#" username="#username#" etc etc>my message</cfmail>

This sends the messages evenly across 2... but how about 7?
Question by:MFredin
    LVL 51

    Accepted Solution

    <cfoutput query="emailAlerts">
          #CurrentRow# #currentRow mod 7#<hr>
          <cfswitch expression="#currentRow mod 7#">
                <cfcase value="1"> server 1 </cfcase>
                <cfcase value="2"> server 2 </cfcase>
                <cfcase value="3"> server 3 </cfcase>
                <cfcase value="4"> server 4 </cfcase>
                <cfcase value="5"> server 5 </cfcase>
                <cfcase value="6"> server 6 </cfcase>
                <cfcase value="0"> server 7 </cfcase>
    LVL 51

    Expert Comment

    ... or use a structure. It's slightly more elegant IMO

    <!--- put server info into a structure --->
    <cfset availableServers = {}>
    <cfset availableServers["0"] = {serverName="server1", user="username 1"}>
    <cfset availableServers["1"] = {serverName="server2", user="username 2"}>
    <cfset availableServers["2"] = {serverName="server3", user="username 3"}>
    <cfset availableServers["3"] = {serverName="server4", user="username 4"}>
    <cfset availableServers["4"] = {serverName="server5", user="username 5"}>
    <cfset availableServers["5"] = {serverName="server6", user="username 6"}>
    <cfset availableServers["6"] = {serverName="server7", user="username 7"}>

    <cfoutput query="emailAlerts">
          <cfset serverIndex = currentRow mod 7>
          <cfset serverName = availableServers[serverIndex].serverName>
          <cfset userName = availableServers[serverIndex].user>
            <cfmail server="#servername#" username="#username#" etc etc>my message</cfmail>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
    The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now