com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required

Hello there

I have configured keycloak 18.0.0 with email settings appropriately feed into realm settings. “Test Connection” works and I get test email on my box. However, when I perform an action that triggers email sending (say creating account with verify email enabled), the email is note sent. Instead I get

2022-05-24 21:39:45,334 ERROR [org.keycloak.authentication.requiredactions.VerifyEmail] (executor-thread-3) Failed to send verification email: org.keycloak.email.EmailException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required

	at org.keycloak.email.DefaultEmailSenderProvider.send(DefaultEmailSenderProvider.java:153)
	at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send(FreeMarkerEmailTemplateProvider.java:264)
	at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send(FreeMarkerEmailTemplateProvider.java:259)
	at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send(FreeMarkerEmailTemplateProvider.java:250)
	at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send(FreeMarkerEmailTemplateProvider.java:207)
	at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.sendVerifyEmail(FreeMarkerEmailTemplateProvider.java:181)
	at org.keycloak.authentication.requiredactions.VerifyEmail.sendVerifyEmail(VerifyEmail.java:160)
	at org.keycloak.authentication.requiredactions.VerifyEmail.requiredActionChallenge(VerifyEmail.java:81)
	at org.keycloak.services.managers.AuthenticationManager.executeAction(AuthenticationManager.java:1327)

After inspecting the logs further, I found out that useAuth is flagged false when sending verification email. Please note that when configuring email settings I have Authentication enabled with username and password correctly defined.

Traceback on Test Connection (email is sent as expected)

[javax.mail] (executor-thread-3) getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
2022-05-24 21:29:59,338 FINE  [com.sun.mail.smtp] (executor-thread-3) useEhlo true, useAuth true
2022-05-24 21:29:59,339 FINE  [com.sun.mail.smtp] (executor-thread-3) trying to connect to host "smtp.example.com", port 587, isSSL false
2022-05-24 21:29:59,341 FINE  [com.sun.mail.smtp] (executor-thread-3) connected to host "smtp.example.com", port: 587
......
2022-05-24 21:29:59,351 FINE  [com.sun.mail.smtp] (executor-thread-3) Found extension "DSN", arg ""
2022-05-24 21:29:59,351 FINE  [com.sun.mail.smtp] (executor-thread-3) Found extension "AUTH", arg "PLAIN LOGIN"
2022-05-24 21:29:59,351 FINE  [com.sun.mail.smtp] (executor-thread-3) protocolConnect login, host=smtp.example.com, user=sender@example.com, password=<non-null>
2022-05-24 21:29:59,352 FINE  [com.sun.mail.smtp] (executor-thread-3) Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
2022-05-24 21:29:59,352 FINE  [com.sun.mail.smtp] (executor-thread-3) Using mechanism LOGIN
2022-05-24 21:29:59,376 FINE  [com.sun.mail.smtp] (executor-thread-3) use8bit false
2022-05-24 21:29:59,518 FINE  [com.sun.mail.smtp] (executor-thread-3) Verified Addresses
2022-05-24 21:29:59,518 FINE  [com.sun.mail.smtp] (executor-thread-3)  receiver@example.com
2022-05-24 21:29:59,544 FINE  [javax.activation] (executor-thread-3) MailcapCommandMap: createDataContentHandler for multipart/alternative
2022-05-24 21:29:59,544 FINE  [javax.activation] (executor-thread-3)   search DB #1
2022-05-24 21:29:59,544 FINE  [javax.activation] (executor-thread-3)   search DB #2
2022-05-24 21:29:59,544 FINE  [javax.activation] (executor-thread-3)   search fallback DB #1
2022-05-24 21:29:59,544 FINE  [javax.activation] (executor-thread-3)     got content-handler
2022-05-24 21:29:59,544 FINE  [javax.activation] (executor-thread-3)       class com.sun.mail.handlers.multipart_mixed
2022-05-24 21:29:59,565 FINE  [com.sun.mail.smtp] (executor-thread-3) message successfully delivered to mail server

Traceback on Verify Email

2022-05-24 21:39:45,311 FINE  [javax.mail] (executor-thread-3) getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
2022-05-24 21:39:45,314 FINE  [com.sun.mail.smtp] (executor-thread-3) useEhlo true, useAuth false
2022-05-24 21:39:45,314 FINE  [com.sun.mail.smtp] (executor-thread-3) trying to connect to host "smtp.example.com", port 587, isSSL false
2022-05-24 21:39:45,316 FINE  [com.sun.mail.smtp] (executor-thread-3) connected to host "smtp.example.com", port: 587
....
2022-05-24 21:39:45,330 FINE  [com.sun.mail.smtp] (executor-thread-3) Found extension "AUTH", arg "PLAIN LOGIN"
2022-05-24 21:39:45,331 FINE  [com.sun.mail.smtp] (executor-thread-3) use8bit false
2022-05-24 21:39:45,331 FINE  [com.sun.mail.smtp] (executor-thread-3) got response code 530, with response: 530 5.7.1 Authentication required

2022-05-24 21:39:45,332 FINE  [com.sun.mail.smtp] (executor-thread-3) MessagingException while sending: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required