Package ch.k43.util
Klasse KSMTPMailer
java.lang.Object
ch.k43.util.KSMTPMailer
Compose and send MIME multipart email to an SMTP host.
Notes:
- The JAR files for jakarta.mail and angus.mail (with the activation classes) must be present in the class path during runtime.
- The default transmission is secured (STARTTLS/TLS) which can be disabled with setSecuredConnection(false)
- If no host name is specified, the highest priority MX DNS record of the first recipient will be used
to connect to the SMTP server on port 25
Example: KSMTPMailer mailer = new KSMTPMailer(); mailer.setFrom("john.doe@acme.com"); mailer.setTo("bob.smith@hotmail.com"); mailer.setSubject("Two files"); mailer.addText("Here are the two files:"); mailer.addFile("file1.txt"); mailer.addFile("file2.txt"); mailer.addText("Regards, John"); mailer.send();
- Seit:
- 2024.05.17
-
Konstruktorübersicht
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungboolean
Add a multipart file item.boolean
Add a multipart HTML item.boolean
Add a multipart text item.boolean
Add a multipart text item.Get last error message.int
Get size of last message sent.boolean
send()
Compose and send the email multi part message.void
setAuthentication
(String argUserName, String argUserPassword) Set user name and password for basic client authentication.void
Set the blind carbon copy address(es).void
Set the carbon copy address(es).void
Set sender address.void
setOAuth2Authentication
(String argUserName, String argAccessToken) Set user name and access token for OAuth 2.0 authentication.void
setReplyTo
(String argReplyToAddress) Set the reply-to address.void
setSecureConnection
(boolean argSecureConnection) Set secure (STARTTLS or TLS) or non-secure connection.
Note: The default is a secured connection.void
setSMTPHost
(String argSMTPHostName, int argSMTPHostPort) Set SMTP host name.
Note: If SMTP host name is not set, the host name from the highest priority MX record for the first recipient address (and the port number 25) is taken.void
setSubject
(String argSubject) Set email subject.void
setSubject
(String argSubject, String argCharSet) Set email subject with given character set.void
Set the recipient address(es).void
setUnsubscribe
(String argLinks) Set unsubscribe mail header.toString()
String representation of object.
-
Konstruktordetails
-
KSMTPMailer
public KSMTPMailer()Class constructor
-
-
Methodendetails
-
addFile
Add a multipart file item.- Parameter:
argFileName
- File name to be attached- Gibt zurück:
- True if success, false otherwise
-
addHTML
Add a multipart HTML item. The passed HTML is saved with UTF-8 charset.- Parameter:
argHTMLBody
- HTML to be added- Gibt zurück:
- True if success, false otherwise
-
addText
Add a multipart text item. The passed text is saved with UTF-8 charset.- Parameter:
argTextBody
- Text to be added- Gibt zurück:
- True if success, false otherwise
-
addText
Add a multipart text item.- Parameter:
argTextBody
- Text to be addedargCharSet
- Character set (e.g. UTF-8)- Gibt zurück:
- True if success, false otherwise
- Seit:
- 2024.06.10
-
getErrorMessage
Get last error message.- Gibt zurück:
- Last error message
-
getMessageSize
public int getMessageSize()Get size of last message sent.- Gibt zurück:
- Size of last message sent
- Seit:
- 2024.05.27
-
send
public boolean send()Compose and send the email multi part message.If no SMTP server was previously set with setSMTPHost(), the message will be sent to the highest priority MX domain from the first recipient found.
- Gibt zurück:
- True if success, false otherwise
-
setAuthentication
Set user name and password for basic client authentication.- Parameter:
argUserName
- User nameargUserPassword
- Password
-
setBCC
Set the blind carbon copy address(es).- Parameter:
argBCCAddresses
- Email address(es) separated by commas
-
setCC
Set the carbon copy address(es).- Parameter:
argCCAddresses
- Email address(es) separated by commas
-
setFrom
Set sender address.- Parameter:
argFromAddress
- Sender email address
-
setOAuth2Authentication
Set user name and access token for OAuth 2.0 authentication. The access token must previously been obtained from the authorization server of the hosting provider.- Parameter:
argUserName
- User nameargAccessToken
- Access token- Seit:
- 2024.06.11
-
setReplyTo
Set the reply-to address.- Parameter:
argReplyToAddress
- Email address
-
setSecureConnection
public void setSecureConnection(boolean argSecureConnection) Set secure (STARTTLS or TLS) or non-secure connection.
Note: The default is a secured connection.- Parameter:
argSecureConnection
- True for secured connection, false otherwise.
-
setSMTPHost
Set SMTP host name.
Note: If SMTP host name is not set, the host name from the highest priority MX record for the first recipient address (and the port number 25) is taken.- Parameter:
argSMTPHostName
- SMTP host nameargSMTPHostPort
- Host port
-
setSubject
Set email subject.- Parameter:
argSubject
- Subject to be set (default is no subject)
-
setSubject
Set email subject with given character set.- Parameter:
argSubject
- Subject to be set (default is no subject)argCharSet
- Character set (e.g."UTF-8")- Seit:
- 2024.06.11
-
setTo
Set the recipient address(es).- Parameter:
argToAddresses
- Email address(es) separated by commas
-
setUnsubscribe
Set unsubscribe mail header.- Parameter:
argLinks
- Unsubscribe HTML link (Example<mailto:unsubscribe@acme.com>,<https://unsubscribe.acme.com>
- Seit:
- 2024.06.19
-
toString
String representation of object.
-