Class OAuth2JavaMailSender

java.lang.Object
org.springframework.mail.javamail.JavaMailSenderImpl
io.jmix.email.authentication.OAuth2JavaMailSender
All Implemented Interfaces:
org.springframework.mail.javamail.JavaMailSender, org.springframework.mail.MailSender

@NullMarked public class OAuth2JavaMailSender extends org.springframework.mail.javamail.JavaMailSenderImpl
JavaMailSenderImpl that authenticates every SMTP connection with a current OAuth2 access token obtained from OAuth2TokenProvider.

The token is passed explicitly as the connection password. A Authenticator must not be used for OAuth2: jakarta.mail.Service caches the password authentication in the Session after the first successful connection and consults the cache before the authenticator, so the first access token would be reused for the lifetime of the session regardless of expiry or refresh token changes.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final OAuth2TokenProvider
     

    Fields inherited from class org.springframework.mail.javamail.JavaMailSenderImpl

    DEFAULT_PORT, DEFAULT_PROTOCOL
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected jakarta.mail.Transport
     

    Methods inherited from class org.springframework.mail.javamail.JavaMailSenderImpl

    createMimeMessage, createMimeMessage, doSend, getDefaultEncoding, getDefaultFileTypeMap, getHost, getJavaMailProperties, getPassword, getPort, getProtocol, getSession, getTransport, getUsername, send, send, setDefaultEncoding, setDefaultFileTypeMap, setHost, setJavaMailProperties, setPassword, setPort, setProtocol, setSession, setUsername, testConnection

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.mail.javamail.JavaMailSender

    send, send, send

    Methods inherited from interface org.springframework.mail.MailSender

    send
  • Field Details

  • Constructor Details

  • Method Details

    • connectTransport

      protected jakarta.mail.Transport connectTransport() throws jakarta.mail.MessagingException
      Overrides:
      connectTransport in class org.springframework.mail.javamail.JavaMailSenderImpl
      Throws:
      jakarta.mail.MessagingException