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
ConstructorsConstructorDescriptionMailAuthenticator(jakarta.mail.PasswordAuthentication auth) Constructs a newMailAuthenticatorwith a pre-existingPasswordAuthenticationobject.MailAuthenticator(String userName, String password) Constructs a newMailAuthenticatorwith the given username and password.MailAuthenticator(MailAccount mailAccount) Constructs a newMailAuthenticatorfrom aMailAccountobject. -
Method Summary
Modifier and TypeMethodDescriptionprotected jakarta.mail.PasswordAuthenticationReturns thePasswordAuthenticationobject containing the credentials.static MailAuthenticatorCreates a newMailAuthenticatorinstance with the given username and password.Methods inherited from class jakarta.mail.Authenticator
getDefaultUserName, getRequestingPort, getRequestingPrompt, getRequestingProtocol, getRequestingSite
-
Constructor Details
-
MailAuthenticator
Constructs a newMailAuthenticatorfrom aMailAccountobject.- Parameters:
mailAccount- TheMailAccountcontaining the username and password.
-
MailAuthenticator
Constructs a newMailAuthenticatorwith 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 newMailAuthenticatorwith a pre-existingPasswordAuthenticationobject.- Parameters:
auth- ThePasswordAuthenticationobject.
-
-
Method Details
-
of
Creates a newMailAuthenticatorinstance with the given username and password.- Parameters:
user- The username for authentication.pass- The password for authentication.- Returns:
- A new
MailAuthenticatorinstance.
-
getPasswordAuthentication
protected jakarta.mail.PasswordAuthentication getPasswordAuthentication()Returns thePasswordAuthenticationobject containing the credentials. This method is called by the Jakarta Mail API to get the authentication details.- Overrides:
getPasswordAuthenticationin classjakarta.mail.Authenticator- Returns:
- The
PasswordAuthenticationobject.
-