Package ch.k43.util

Klasse KSMTPMailer

java.lang.Object
ch.k43.util.KSMTPMailer

public class KSMTPMailer extends Object
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

    Konstruktoren
    Konstruktor
    Beschreibung
    Class constructor
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    boolean
    addFile(String argFileName)
    Add a multipart file item.
    boolean
    addHTML(String argHTMLBody)
    Add a multipart HTML item.
    boolean
    addText(String argTextBody)
    Add a multipart text item.
    boolean
    addText(String argTextBody, String argCharSet)
    Add a multipart text item.
    Get last error message.
    int
    Get size of last message sent.
    boolean
    Compose and send the email multi part message.
    void
    setAuthentication(String argUserName, String argUserPassword)
    Set user name and password for basic client authentication.
    void
    setBCC(String argBCCAddresses)
    Set the blind carbon copy address(es).
    void
    setCC(String argCCAddresses)
    Set the carbon copy address(es).
    void
    setFrom(String argFromAddress)
    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
    setTo(String argToAddresses)
    Set the recipient address(es).
    void
    Set unsubscribe mail header.
    String representation of object.

    Von Klasse geerbte Methoden java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Konstruktordetails

    • KSMTPMailer

      public KSMTPMailer()
      Class constructor
  • Methodendetails

    • addFile

      public boolean addFile(String argFileName)
      Add a multipart file item.
      Parameter:
      argFileName - File name to be attached
      Gibt zurück:
      True if success, false otherwise
    • addHTML

      public boolean addHTML(String argHTMLBody)
      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

      public boolean addText(String argTextBody)
      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

      public boolean addText(String argTextBody, String argCharSet)
      Add a multipart text item.
      Parameter:
      argTextBody - Text to be added
      argCharSet - Character set (e.g. UTF-8)
      Gibt zurück:
      True if success, false otherwise
      Seit:
      2024.06.10
    • getErrorMessage

      public String 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

      public void setAuthentication(String argUserName, String argUserPassword)
      Set user name and password for basic client authentication.
      Parameter:
      argUserName - User name
      argUserPassword - Password
    • setBCC

      public void setBCC(String argBCCAddresses)
      Set the blind carbon copy address(es).
      Parameter:
      argBCCAddresses - Email address(es) separated by commas
    • setCC

      public void setCC(String argCCAddresses)
      Set the carbon copy address(es).
      Parameter:
      argCCAddresses - Email address(es) separated by commas
    • setFrom

      public void setFrom(String argFromAddress)
      Set sender address.
      Parameter:
      argFromAddress - Sender email address
    • setOAuth2Authentication

      public void setOAuth2Authentication(String argUserName, String argAccessToken)
      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 name
      argAccessToken - Access token
      Seit:
      2024.06.11
    • setReplyTo

      public void setReplyTo(String argReplyToAddress)
      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

      public 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.
      Parameter:
      argSMTPHostName - SMTP host name
      argSMTPHostPort - Host port
    • setSubject

      public void setSubject(String argSubject)
      Set email subject.
      Parameter:
      argSubject - Subject to be set (default is no subject)
    • setSubject

      public void setSubject(String argSubject, String argCharSet)
      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

      public void setTo(String argToAddresses)
      Set the recipient address(es).
      Parameter:
      argToAddresses - Email address(es) separated by commas
    • setUnsubscribe

      public void setUnsubscribe(String argLinks)
      Set unsubscribe mail header.
      Parameter:
      argLinks - Unsubscribe HTML link (Example <mailto:unsubscribe@acme.com>,<https://unsubscribe.acme.com>
      Seit:
      2024.06.19
    • toString

      public String toString()
      String representation of object.
      Setzt außer Kraft:
      toString in Klasse Object
      Seit:
      2024.08.23