Search code examples
emailspring-bootjakarta-mail

Disable javamail email address validation


Id like my application to have bare minimum 'To' email address validation, that is only empty string is considered to be invalid. All the below strings are to be considered as valid email addresses from my application perspective:

  • adas.assa.com
  • sdaassa.com
  • sada

Im using spring-boot-mail starter to develop my application, and MimeMessageHelper to construct the mail message. And java mail api would issue sendFailedException Invalid Address, when I tried to send email to those addresses. From my digging it seems that there are already built in email address validations. Is there any way that I can disable the email address validations, so that my application still send email to those addresses?


Update since @Bill Shannon:-
I've updated my properties file as so:
spring.mail.properties.mail.mime.address.strict=false

Im still getting the error:

org.springframework.mail.MailSendException: Failed messages: javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 501 5.1.3 Invalid address

Im not sure if it has to do with how I pass the session properties as you @Bill mentioned, or coming from exhange server address validation(can we tell from the error?).


Update after checking with exchanger server admin.

It works. The error received actually issue by email server. You have to get your email server to disable email address validation to make it work.


Solution

  • Try setting the Session property mail.mime.address.strict to "false". Still, it's up to your mail server whether it will accept those addresses.