Module bus.extra

Class MailAuthenticator

java.lang.Object
jakarta.mail.Authenticator
org.miaixz.bus.extra.mail.MailAuthenticator

public class MailAuthenticator extends jakarta.mail.Authenticator
An authenticator that provides username and password authentication for a mail session. This class extends Authenticator and is used to supply credentials to the mail server.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
    MailAuthenticator(jakarta.mail.PasswordAuthentication auth)
    Constructs a new MailAuthenticator with a pre-existing PasswordAuthentication object.
    MailAuthenticator(String userName, String password)
    Constructs a new MailAuthenticator with the given username and password.
    Constructs a new MailAuthenticator from a MailAccount object.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected jakarta.mail.PasswordAuthentication
    Returns the PasswordAuthentication object containing the credentials.
    of(String user, String pass)
    Creates a new MailAuthenticator instance with the given username and password.

    Methods inherited from class jakarta.mail.Authenticator

    getDefaultUserName, getRequestingPort, getRequestingPrompt, getRequestingProtocol, getRequestingSite

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MailAuthenticator

      public MailAuthenticator(MailAccount mailAccount)
      Constructs a new MailAuthenticator from a MailAccount object.
      Parameters:
      mailAccount - The MailAccount containing the username and password.
    • MailAuthenticator

      public MailAuthenticator(String userName, String password)
      Constructs a new MailAuthenticator with the given username and password.
      Parameters:
      userName - The username for authentication.
      password - The password for authentication.
    • MailAuthenticator

      public MailAuthenticator(jakarta.mail.PasswordAuthentication auth)
      Constructs a new MailAuthenticator with a pre-existing PasswordAuthentication object.
      Parameters:
      auth - The PasswordAuthentication object.
  • Method Details

    • of

      public static MailAuthenticator of(String user, String pass)
      Creates a new MailAuthenticator instance with the given username and password.
      Parameters:
      user - The username for authentication.
      pass - The password for authentication.
      Returns:
      A new MailAuthenticator instance.
    • getPasswordAuthentication

      protected jakarta.mail.PasswordAuthentication getPasswordAuthentication()
      Returns the PasswordAuthentication object containing the credentials. This method is called by the Jakarta Mail API to get the authentication details.
      Overrides:
      getPasswordAuthentication in class jakarta.mail.Authenticator
      Returns:
      The PasswordAuthentication object.