Reputation: 252
code:
<cfmail query="getEmail"
to="#getEmail.email#"
from="#getEmail.displayName# <#getEmail.emailfrom#>"
subject="#getEmail.emailsubject#"
type="html"
server="10.1.0.2"
timeout="360"
username="#myuser#"
password="#mypassword#" spoolenable='no' >
My email content
</cfemail>
Im running cfmail tag with query. how can i use isvalid("email",'') in my situation.
Upvotes: 0
Views: 502
Reputation: 41
I discovered that an email address like this...
<cfset new_Emailaddress = '?é?á[email protected]'>
<cfset blnValid = #IsValid("email", new_Emailaddress)# />
<cfset email_test_result = #YesNoFormat( blnValid )#>
<cfoutput>#email_test_result#</cfoutput>
(try it, code will output "yes")
BUT the ColdFusion mail server will bomb when attempting a message addressed to ?é?á[email protected]. (Tested on CF 2016)
"..Attribute validation error for tag CFMAIL.The value of the attribute to, which is currently ?é?á[email protected], is invalid. ..."
I want to add to the accepted answer that one can't rely on the isvalid ColdFusion function alone. I suggest one filter unlikely email address characters too.
<cfset new_Emailaddress2 = ReReplaceNoCase(new_Emailaddress,"[\)|\(|\<|\>|\?|\=|##|\$|\%|\^|\&|\*|\!|\é|\á]","","ALL")>
<cfoutput>#new_Emailaddress#</cfoutput><br>
<cfoutput>#new_Emailaddress2#</cfoutput>
Upvotes: 0
Reputation: 111
Try your code inside a cfif tag.
<cfloop query="getEmail">
<cfif isValid("email", getEmail.email)>
//Code to send mail
<cfelse>
Invalid Email <cfoutput>#email#</cfoutput>.
</cfif>
</cfloop>
Here, an email you're getting from getEmail query. If it is valid then only email will be sent, else the email won' be sent. Ultimately you will find the list of Invalid emails (if any).
Upvotes: 2
Reputation: 306
Maybe u can use regex on your SQL query, try putting this condition
SELECT .... WHERE email NOT REGEXP '^[^@]+@[^@]+\.[^@]{2,}$'
I believe this return only records with valid emails.
let me know if this works
Upvotes: 1