cfmail only validates emails when spooling

Description

if you omit the from address for cfmail it throws an error, however, it's only when the mail is spooled, that email addresses are parsed using javax.mail.internet.InternetAddress and maybe set to null if they are invalid.

https://github.com/lucee/Lucee/blob/5.3/core/src/main/java/lucee/runtime/net/mail/MailUtil.java#L189

It would be more developer friendly if these processing/checks via javax.mail.internet.InternetAddress were applied before spooling, i.e when the cfmail tag is called so an exception can be thrown (i.e. invalid email address)

Environment

None

Activity

Show:
Tom Chiverton
September 9, 2020, 1:34 AM

it’s not as simple as just using isvalid('email',) because Mail needs to take a list of addresses for things like the to and cc fields so it’d have to be tokenized too. At least isValid() believes in CC TLD and real names though :)

Zac Spitzer
September 9, 2020, 2:11 AM
Edited

agreed on isValid, that’s why i have subsequently suggested using the spool validate. It’s always going to be run anyway.

previously Lucee would keep retrying even if the spool validate failed (unlike a delivery problem) so, there’s no mail retrying as it will only fail once.

it does make sense to put this behind a flag, which is disabled by default as developers might not expect an exception sending a mail, unless they are using async=false

adding something like a <cfmail validate=”true|false”> (default false) for this makes sense, then in application.cfc, this.tag.mail.validate=true; could be used to enable it.

Michael Offner
September 15, 2020, 3:46 AM

changed the implementation

Tom Chiverton
September 16, 2020, 11:35 PM

Err, OK, what about the other stuff like making the behaviour change an opt-in option ?

Zac Spitzer
September 16, 2020, 11:50 PM

as it was always going to fail whilst spooling anyway, if you don’t really care, you can always just wrap it up in a try, catch and ignore

PR to update cfmail [to] be a required attribute

Fixed

Assignee

Pothys - MitrahSoft

Reporter

Zac Spitzer

Priority

Major

Fix versions

Sprint

5.3.8 Sprint 3

Affects versions