3 Replies Latest reply on Dec 11, 2012 2:13 AM by BKBK

    CFMAIL error when encountering bad address

    sakonnetweb Level 1

      Hello

       

      I have an app running with approx 6,000 signees. I try to ensure their email going in the DB is validated via javascript- but this not totally effective.

       

      What code could I write in the CFmail tag that would ignore bad emails, send the meassage without errors, and perhaps even list the bad mail addresses?

       

      Thanks in advance

       

      Norman B.

        • 1. Re: CFMAIL error when encountering bad address
          Dan Bracuk Level 5

          ColdFusion has an isValid tag that can be used to ensure the address has the proper structure.  Ensuring that it represents an actual email address is something else altogether.

          • 2. Re: CFMAIL error when encountering bad address
            Adam Cameron. Level 5

            I try to ensure their email going in the DB is validated via javascript- but this not totally effective.

             

             

            One should never rely solely on client-side validation for this sort of thing, as it can be defeated reasonably easily.  Your validation should alwyas first and foremost be on the server side where you can guarantee it will run, client-side validation should be considered more UI sugar than actual validation.

             

            That said, if you have junk data in your DB, you need to do what Dan suggests: validate the data and report back on which data is bung.  I would not do this at the time you come to be sending the email I'd do it as an exercise immediately after fixing your validation so it's done server side, so that the data in your DB is all valid.

             

            --

            Adam

            • 3. Re: CFMAIL error when encountering bad address
              BKBK Adobe Community Professional & MVP

              You may have to validate the e-mails one by one. You could loop through the e-mail addresses, and do something like

               

              <cfloop>

              <cfset isFromEmailValid = isValid("email", fromEmail)>

              <cfset isToEmailValid = isValid("email", toEmail)>

              <cfset isSubjectValid = len(trim(subject))>

               

              <cfif isFromEmailValid and isToEmailValid and isSubjectValid>

                  <cfmail from="#fromEmail#" to="#toEmail#" subject="#subject#"></cfmail>

                <cfelse>

                  <!--- log details of unsent mail--->

                </cfif>

               

              </cfloop>

               

              However, as you can easily guess, this method is unsuitable for large e-mail jobs

               

              [Edited: my initial response had crossed Adam's on the wire.]