Class ZSMTPMail

java.lang.Object
org.spiderwiz.zutils.ZSMTPMail
All Implemented Interfaces:
ZMail

public class ZSMTPMail
extends Object
implements ZMail
Implementation of ZMail for SMTP mail.

This implementation is invoked by Spiderwiz framework when [mail system] property in the application's configuration file includes the smtp parameter.

SMTP mail configuration example:

[mail system]smtp;server=smtp.gmail.com;user=zvilif@spiderwiz.org;pwd=dumptrump;port=465;ssl

  • Constructor Details

  • Method Details

    • configure

      public void configure​(Map<String,​String> configParams)
      Configures SMTP mail using the given configuration map.

      The configuration map maps configuration parameters to values. SMTP configuration parameters are:

      server= the SMTP server to use.

      user= username to login with.

      pwd= password to login with.

      port= server port to use.

      ssl - include this keyword if SSL protocol shall be used.

      tls - include this keyword if TLS protocol shall be used.

      Example:

      server=smtp.gmail.com;user=zvilif@spiderwiz.org;pwd=dumptrump;port=465;ssl

      Specified by:
      configure in interface ZMail
      Parameters:
      configParams - the configuration map.
    • send

      public void send​(String from, String to, String cc, String subject, String body, boolean html, boolean highPriority) throws MessagingException, UnsupportedEncodingException
      Sends a message via an SMTP server.
      Specified by:
      send in interface ZMail
      Parameters:
      from - the mail address of the sender.
      to - the mail address(es) of the addressee(s). Multiple addresses shall be concatenated by a comma(,) or a semicolon(;).
      cc - if not null, sends a carbon copy to the specified address(es). Multiple addresses shall be concatenated by a comma(,) or a semicolon(;).
      subject - the mail subject or null if there is no subject.
      body - the mail body or null if there is no body.
      html - true if the message shall be sent in HTML format, false if it shall be sent as plain text.
      highPriority - true if the message shall be flagged as high priority.
      Throws:
      MessagingException
      UnsupportedEncodingException
    • getSmtpServer

      protected String getSmtpServer()
      Gets the configured SMTP server.
      Returns:
      the configured SMTP server
    • setSmtpServer

      protected void setSmtpServer​(String smtpServer)
      Configures an SMTP server
      Parameters:
      smtpServer - SMTP server name.
    • getSmtpPort

      protected String getSmtpPort()
      Gets the configured SMTP port number.
      Returns:
      the configured SMTP port number
    • setSmtpPort

      protected void setSmtpPort​(String smtpPort)
      Configures an SMTP port number.
      Parameters:
      smtpPort - SMTP port number.
    • getSmtpMode

      protected ZSMTPMail.Mode getSmtpMode()
      Gets the configured SMTP security mode.
      Returns:
      PLAIN for no security, SSL or TLS.
    • setSmtpMode

      protected void setSmtpMode​(ZSMTPMail.Mode smtpMode)
      Configures SMTP security mode.
      Parameters:
      smtpMode - PLAIN for no security, SSL or TLS.
    • getUsername

      protected String getUsername()
      Gets the configured username to login to the SMTP server with.
      Returns:
      the configured username to login to the SMTP server with.
    • setUsername

      protected void setUsername​(String username)
      Configures the username to login to the SMTP server with.
      Parameters:
      username - the username to login to the SMTP server with.
    • getPassword

      protected String getPassword()
      Gets the configured password to login to the SMTP server with.
      Returns:
      the configured password to login to the SMTP server with.
    • setPassword

      protected void setPassword​(String password)
      Configures the password to login to the SMTP server with.
      Parameters:
      password - the password to login to the SMTP server with.