[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Send email from multiple servers evenly by looping over query

Posted on 2011-05-06
Medium Priority
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="test.com">
<cfset username = "un"> etc etc


<cfset servername="test22.com">
<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
  • 2
LVL 52

Accepted Solution

_agx_ earned 2000 total points
ID: 35709688
<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 52

Expert Comment

ID: 35709747
... 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>

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 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