Using CFTHROW to catch invalid email addresses

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Using CFTHROW to catch invalid email addresses

    I'm working on a helpdesk system that sends notification emails to users and
    support consultants whenever they updated certain fields in the forms.
    Unfortunately they want users to be able to add free-form email addresses to
    the CC fields of the email. Our mail server is set so that if any of the
    addresses does not exist then the email does not send. I don't know if this is
    the way all mail servers work, but this one does and there is no changing it.

    So I used CFTry and Catch to snag any bad addresses, but using CFCatch.Detail
    only tells me "User Unknown" Actually I get the following:
    This exception was caused by: javax.mail.SendFailedException: Invalid
    Addresses; nested exception is: javax.mail.SendFailedException: 550 5.1.1 ...
    User unknown .

    But if I look at the mail log in the administrator it says:
    Invalid Addresses; nested exception is: javax.mail.SendFailedException: 550
    5.1.1 <cc@caris.com>... User unknown

    So something knows which address is wrong and if I could find it then I could
    tell users exactly which address is causing the problem. My question is, what
    does the coldfusion administrator use to display the nonexistant email address,
    [email]cc@caris.com[/email]? Is there a JAVA object that holds this variable that I could use
    CFOBJECT and CFTHROW to display it?

    Any help would be greatly appreciated.
    Thanks


    Ashburton Guest

  2. Similar Questions and Discussions

    1. Email to different addresses
      Hi, I am designing a site for a company with dealers in different countries. For each product I have a 'request info' form with name, address,...
    2. #25342 [Opn->Bgs]: function gethostbynamel. This is returning ip addresses for invalid domains
      ID: 25342 Updated by: pollita@php.net Reported By: getsuryya at rediffmail dot com -Status: Open +Status: ...
    3. #25342 [NEW]: function gethostbynamel. This is returning ip addresses for invalid domains
      From: getsuryya at rediffmail dot com Operating system: LINUX PHP version: 4.3.2 PHP Bug Type: *Network Functions Bug...
    4. hiding email addresses
      Could you tell me how to avoid having automated programs pick up the email addresses on your website so we avoid receiving so much junkmail? ...
  3. #2

    Default Re: Using CFTHROW to catch invalid email addresses

    I cannot easily duplictae this situation but I do know that CFCATCH creates
    various undocumented variables -- depending on the exception type.

    See the comments
    [url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/[/url]
    wwhelp.htm?context=ColdFusion_Documentation&file=0 0000225.htm for example.

    You might find the information you need by adding:
    <CFDUMP var="#CFCatch#">
    to your page, temporarily, while triggering this exception type.

    Cheers,
    -- MikeR


    MikerRoo Guest

  4. #3

    Default Re: Using CFTHROW to catch invalid email addresses

    there are a variey of exceptions from javamail that you can trap. the
    javax.mail.SendFailedException is always associated with email that could not
    be sent (btw that's not the same thing as a bad address). that exception has 3
    methods that you can use to query the state of your sent mail:

    getValidSentAddresses() returns an array of valid addresses that were sent ok
    getValidUnsentAddresses() returns an array of valid addresses that weren't
    sent (server down, etc.)
    getInvalidAddresses() returns an array of invalid addresses that weren't sent
    (bad addresses)

    note that what javamail thinks is a valid email address is laxer than what
    most folks think. for instance joe@.com will pass javamail's address parse even
    when it's set to strict. i'm not sure if that qualifies as kosher according to
    the RFC but javamail certainly does.


    PaulH Guest

  5. #4

    Default Re: Using CFTHROW to catch invalid email addresses

    Thanks PaulH. I saw the getInvalidAddresses() method in my research and played
    around with it a bit, but due to my lack of knowledge with JAVA I couldn't get
    it to work. How do I use this in ColdFusion to have it return the invalid
    addresses?

    Ashburton Guest

  6. #5

    Default Re: Using CFTHROW to catch invalid email addresses

    i'm at home, i'll see what i have when i get into the office tomorrow.
    PaulH Guest

  7. #6

    Default Re: Using CFTHROW to catch invalid email addresses

    i think my original message was a bit misleading (i was thinking about using
    javamail directly) as cf muddles the javamail exception a bit. see the code
    below. some things to note:
    our mailservers pass on all valid address email so my testing isn't all that
    thorough
    this only traps invalid email addresses (javamail bad address parse), so you
    might be better off simply scrubbing the addresses first (see my first point)
    you need to turn spooling off for this to work (you can do it via the cfmail
    tag) otherwise bad email simply sits in the undelivered folder


    <cftry>
    <!--- send your mail, don't forget to turn OFF spooling if you want this to
    work--->
    <cfcatch type="Any">
    <cfif cfcatch.detail contains "javax.mail.SendFailedException">
    <cfset invalidAddresses="">
    <cfloop index="i" from="1"
    to="#arrayLen(cfcatch.rootCause.InvalidAddresses)# ">
    <cfset
    invalidAddresses=listAppend(invalidAddresses,cfcat ch.rootCause.InvalidAddresses[
    i].toString())>
    </cfloop>
    </cfif>
    </cfcatch>
    </cftry>

    <cfdump var="#InvalidAddresses#">

    PaulH Guest

  8. #7

    Default Re: Using CFTHROW to catch invalid email addresses

    Sweet! That worked like a charm. Thanks a million.
    Ashburton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139