I have a CF page written that gets called by the scheduler once every 15
minutes to look for e-mail in a POP mailbox, and if it meets criteria,
distribute it to the list members.  I've tested it out with no problems, and
3 list members had used it fine until yesterday afternoon.  One list member
sent a message to it, and instead of it going to each of the 26 recipients
one time - it went to each of the 26 recipients 26 times - oops!

Is there anything here in the code here that seems like it could cause this
stuck in a loop problem?  I'm thinking about revising it so that the message
is inserted into a database first and not held by CFX_POP3.  Then, if the
message meets the criteria, select it back out and send it to the recipients
and flag it as a sent message so it doesn't get sent again.

I'm using the CFX_POP3 tag to check the mail:

<CFX_POP3 SERVER="mail.server.name"
PORT="110"
USERNAME="loginname"
PASSWORD="password"
ACTION=""> NAME="bnimailapp"
>

<!--- if there are messages do something --->
<cfif CFX_POP3.MessageCount GT 0>
<cfset delCount = 0>
<cfset mailCount = 0>

<cfloop query="bnimailapp">

<!--- looks for BNI in the subject line, or if it came from montcocc.org
--->  
<cfif FindNoCase("BNI",bnimailapp.Subject,1) OR
FindNoCase("montcocc",bnimailapp.From,1)> <!--- ok - msg is good --->
  <cfif bnimailapp.html is not ""><!--- check to see if content is HTML --->

  <!--- get the recipients --->
  <cfquery name="selActive" datasource="#Session.DSN#">
SELECT tblBni.Email
FROM tblBni
WHERE tblBni.active
   </cfquery>

<!--- send out the message as HTML since HTML was present in the original
email --->
    <cfloop query="selActive">
<cfmail to="#trim(selActive.Email)#" from="#trim(bnimailapp.from)#"
subject="#trim(bnimailapp.Subject)#" type="HTML">
#bnimailapp.html#
</cfmail>
    </cfloop>
<!--- END HTML e-mail --->
   <cfelse><!--- No HTML content - proceed as plain text --->

<cfquery name="selActive" datasource="#Session.DSN#"><!--- get the
recipients --->
  SELECT tblBni.Email
  FROM tblBni
  WHERE tblBni.active
</cfquery>
<cfloop query="selActive">
<cfmail  query="selActive" to="#trim(selActive.Email)#"
from="#trim(bnimailapp.from)#" subject="#trim(bnimailapp.Subject)#">
#bnimailapp.body#
</cfmail>
</cfloop>
</cfif>
<cfset mailCount = mailCount +1><!--- used for logging to --->

<cfquery name="updMailLog" datasource="#Session.DSN#"><!--- log date,
sender, subject and recipients --->
  INSERT into tblMailLog (m_date, m_from, m_subject, m_recipients)
    VALUES
(now(),'#bnimailapp.from#','#left(bnimailapp.subject,253)#',#selActive.Recor
dCount#)
</cfquery>

<!--- no delete the message from the server --->
<CFX_POP3 SERVER="mail.server.name"
PORT="110"
USERNAME="username"
PASSWORD="password"
ACTION=""> UID="#bnimailapp.UID#">

<cfelse><!--- message is bad and did not have BNI in subject line or come
from montcocc.org --->

<!--- create a log entry but with 0 recipients since we did not relay this
mail to the list --->
<cfquery name="updMailLog" datasource="#Session.DSN#"><!--- log date,
sender, subject and recipients --->
  INSERT into tblMailLog (m_date, m_from, m_subject, m_recipients)
   VALUES
(#CreateODBCDateTime(Now())#,'#bnimailapp.from#','SPAM-#left(bnimailapp.subj
ect,253)#',0)
</cfquery>

<!--- delete the bad message --->
  <CFX_POP3 SERVER="mail.server.name"
    PORT="110"
    USERNAME="username"
    PASSWORD="password"
    ACTION="">     UID="#bnimailapp.UID#">
   <cfset delCount = delCount +1>
  </cfif>
</cfloop>

</cfif> <!--- close main condition of if messages are present --->
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to