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

CFMAIL test mode?

New Here ,
Dec 08, 2008 Dec 08, 2008
I have a query that is pulling email addresses from a user database (an older database in this case). Then the query results are being looped into a CFMAIL tag.

Is there a way to test the CFMAIL tag before it actually sends the email to prevent the script from crashing 50 records in if it finds a defunct email?

I've wrapped the CFMAIL in a <cfif> to prevent bad emails being passed in...but it's not fool proof. I don't want to run the script again only to have it crash not knowing what broke it!

How do I deal with something like this?

I've run the query and created a filter and output the email addresses so I could see with my own eyes what is passing to CFMAIL. Looks good so far, but with 750+ emails...I'm sure I could over look something.

Ugh.

Paul
1.9K
Translate
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
LEGEND ,
Dec 08, 2008 Dec 08, 2008
- you can wrap your cfmail in a cftry/cfcatch block
- use FAILTO attribute of cfmail tag to specify an email address
delivery failure notifications should be sent to

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
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
New Here ,
Dec 09, 2008 Dec 09, 2008
Ahh..yes. I've never really had to use the cftry/catch, but sounds like a good solution, as well as your other one about failto parameter. Off to work...thanks!

Paul
Translate
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
LEGEND ,
Dec 09, 2008 Dec 09, 2008
What are you doing with your current if/else logic?
Translate
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
New Here ,
Dec 09, 2008 Dec 09, 2008
Well...after doing some manual filtering using some regex to help me clean up the list. I've narrowed it down to only needing to check for blank email addresses and multiple addresses in a single field.

Thanks
Translate
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
New Here ,
Dec 09, 2008 Dec 09, 2008
Why is this code not working...it's still crashing and giving me a CF error:

<cftry>

<cfmail to="" from="noreply@paulferree.com" failto="paulferree@gmail.com" subject="Test email" >
This is a test
</cfmail>

<cfcatch type="any">
An error has occurred.<br>
<cfdump var="#cfcatch#">
</cfcatch>

</cftry>
Translate
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
LEGEND ,
Dec 09, 2008 Dec 09, 2008
paulferree wrote:
> Why is this code not working...it's still crashing and giving me a CF error:
>

Because you have a syntax error. Syntax errors are found at time of
compilation. <try><catch> blocks can only handle errors during
execution after the code has been compiled.
Translate
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
LEGEND ,
Dec 09, 2008 Dec 09, 2008
paulferree wrote:
> Why is this code not working...it's still crashing and giving me a CF error:
>

Because you have a syntax error. Syntax errors are found at time of
compilation. <try><catch> blocks can only handle errors during
execution after the code has been compiled.

This more legitimate code example should show the behavior you desire.

<cftry>
<cfset bademail = "">
<cfmail to="#bademail#" from="noreply@paulferree.com"
failto="paulferree@gmail.com"
subject="Test email" >
This is a test
</cfmail>

<cfcatch type="any">
An error has occurred.<br>
<cfdump var="#cfcatch#">
</cfcatch>

</cftry>
Translate
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
New Here ,
Dec 09, 2008 Dec 09, 2008
Ahhh...I see now.

But really, this error only occurs when the To: value is zilch...which can just be handled in a cfif before the cfmail is run. So hopefully I wouldn't run into this problem.

Thank you.
Paul
Translate
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
LEGEND ,
Dec 09, 2008 Dec 09, 2008
paulferree wrote:
> Ahhh...I see now.
>
> But really, this error only occurs when the To: value is zilch...which can
> just be handled in a cfif before the cfmail is run. So hopefully I wouldn't
> run into this problem.
>
> Thank you.
> Paul
>

That is true, the try-catch will handle a wider range of issues, but if
you are just looking for empty or otherwise mal-formed email address an
if statement will do as well. Especially if combined with the
isvalid('email',...) function.
Translate
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
LEGEND ,
Dec 09, 2008 Dec 09, 2008
quote:

Originally posted by: paulferree
Well...after doing some manual filtering using some regex to help me clean up the list. I've narrowed it down to only needing to check for blank email addresses and multiple addresses in a single field.

Thanks

If these addresses are coming from a database, you can use the where clause of your query to filter out the blank ones.

If you are storing multiple addresses in a single field, your db design has a lot of room for improvement.
Translate
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
New Here ,
Dec 09, 2008 Dec 09, 2008
I agree...my biggest problem has been dealing with a preexisting database that I did not develop. So trying to handle these legacy exceptions have been quite an effort.

Paul
Translate
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
Guest
Dec 09, 2008 Dec 09, 2008
You could have just done a check with the IsValid() function and if the email is valid then proceed with the cfmail else do whatever needs to be done with non valid records in the database.
Translate
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
New Here ,
Dec 09, 2008 Dec 09, 2008
What is "the" isValid() function?

Translate
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
LEGEND ,
Dec 09, 2008 Dec 09, 2008
LATEST
quote:

Originally posted by: paulferree
What is "the" isValid() function?



It's something you could have used had you not been storing lists of email addresses in single fields. If you are able, you should do something about that.
Translate
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
LEGEND ,
Dec 09, 2008 Dec 09, 2008
paulferree wrote:
> What is "the" isValid() function?
>
>

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_in-k_37.html

Description

Tests whether a value meets a validation or data type rule.
Translate
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