• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

validating email

Participant ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

Hello, I have a program that loops over a comma delimited list of email addresses to send out our newsletters. I am running into the problem with CF MX that if it reaches a bad email it will crash the program and throw an error.

Does anyone know how I could go about validating the email accounts, or weed out the bad ones before I run the code to send out? Here is how I send out the mail:

<cffile action="read"
file="#ExpandPath('contacts.txt')#"
variable="contacts">

<!---loop over the list and send an email to each address--->
<cfloop list="#contacts#" index="idx" delimiters=",">

<cfmail to="#idx#"
from="#Form.MessageFrom#"
subject="#FORM.messageSubject#" type="html">


#form.message#

</cfmail>
Sending to... <cfoutput>"<strong>#idx#</strong>"<br>

</cfoutput>
</cfloop>
TOPICS
Advanced techniques

Views

218

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , May 20, 2008 May 20, 2008
Thanks Dan. I did some research and I came up with some code that fixed what I needed to do. Just wanted to share what is working.

<cffile action="read"
file="#ExpandPath('briantest.txt')#"
variable="contacts">




<!--- Create a table to output the results. --->
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<strong> Email</strong>
</td>
<td width="100">
<strong> Valid?</strong>
</td>
<td width="100">
<strong> Sent?</strong>
</td>
</tr>

<!--- Loop over the emails...

Votes

Translate

Translate
LEGEND ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

Use the validate function. Details are in the cfml reference manual. If you don't have one, the internet does.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2008 May 20, 2008

Copy link to clipboard

Copied

LATEST
Thanks Dan. I did some research and I came up with some code that fixed what I needed to do. Just wanted to share what is working.

<cffile action="read"
file="#ExpandPath('briantest.txt')#"
variable="contacts">




<!--- Create a table to output the results. --->
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<strong> Email</strong>
</td>
<td width="100">
<strong> Valid?</strong>
</td>
<td width="100">
<strong> Sent?</strong>
</td>
</tr>

<!--- Loop over the emails and validate them. --->
<cfloop list="#contacts#" index="idx" delimiters=",">

<!--- Try sending out email. --->
<cftry>

<!--- Send mail. --->
<cfmail
to="#idx#"
from="#Form.MessageFrom#"
subject="#FORM.messageSubject#" type="html">

#form.message#
</cfmail>

<!--- Set success flag. --->
<cfset blnEmailSuccess = true />

<!--- Catch email errors. --->
<cfcatch>

<!--- Email failed. Set success flag. --->
<cfset blnEmailSuccess = false />

</cfcatch>

</cftry>

<cfoutput>
<!--- Check for validity. --->
<cfset blnValid = IsValid( "email", #idx# ) />

<tr>
<td>
#idx#
</td>
<td>
#YesNoFormat( blnValid )#
</td>
<td>
#YesNoFormat( blnEmailSuccess )#
</td>
</tr>
</cfoutput>
</cfloop>
</table>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation