Class MailSender

java.lang.Object
com.groiss.util.MailSender

public class MailSender extends Object
Use the methods in this class for sending SMTP mails.
  • Method Details

    • getDefaultSender

      public static MailSender getDefaultSender()
      Returns a default MailSender which properties are taken from configuration:
      • SMTP host under Configuration/Communication
      • Mail sender under Configuration/Communication
      • SMTP Username under Configuration/Communication
      • SMTP Password under Configuration/Communication
      • Type of SMTP communication under Configuration/Communication
      • MailSender.MailAction defined under Configuration/Communication
      • MailQueue is allowed
      Returns:
      the MailSender
    • getSenderForMailBox

      public static MailSender getSenderForMailBox(MailBox mb)
      Returns a MailSender which properties are taken from a mailbox. If no smtphost is specified for the mailbox, the default sender getDefaultSender() is returned.
      • SMTP hostfrom mailbox
      • Mail senderfrom mailbox
      • SMTP Usernamefrom mailbox
      • SMTP Passwordfrom mailbox, or the OAuth access token, if an authorizer is specified at the mailbox
      • Type of SMTP communicationfrom mailbox
      • MailSender.MailAction defined under Configuration/Communication
      • MailQueue is allowed
      Parameters:
      mb - the mailbox
      Returns:
      the MailSender
    • isMailQueueAllowed

      public boolean isMailQueueAllowed()
      determine, if mail queue should be used
    • getCommunicationType

      public String getCommunicationType()
      Returns:
      the communicationType
    • setCommunicationType

      public void setCommunicationType(String type)
      Sets the communication type. Allowed only, if MailSender.MailAction is NO_QUEUE!
    • getHost

      public String getHost()
      return the smtp host
    • getSender

      public String getSender()
      return the sender address
    • getMessage

      public Message getMessage()
      HINT: Use MessageTemplate interface!
      Returns:
      the last message sent by one of this MailSender send-methods
    • getPort

      public int getPort()
      Returns:
      the configured SMTP Port
    • setSender

      public void setSender(String mailAddress)
      Sets an alternative sender.
      Parameters:
      mailAddress -
    • getSenderCredentials

      public Pair<String,String> getSenderCredentials()
      Get the sender credentials
      Returns:
      a Pair of username/password
    • setSenderAndCredentials

      public void setSenderAndCredentials(String mailAddress, String uname, String passwd)
      Sets alternative sender credentials.
      Parameters:
      mailAddress - the mail address of user
      uname - the user name
      passwd - the password of given user
    • setSMTPHost

      public void setSMTPHost(String smtphost)
      Sets alternative SMTP host (+ optionally SMTP port, separated by colon). Allowed only, if MailSender.MailAction is NO_QUEUE!
      Parameters:
      smtphost -
    • setMailAction

      public void setMailAction(MailSender.MailAction action)
    • getMailAction

      public MailSender.MailAction getMailAction()
      Returns:
      the current MailSender.MailAction
    • getMailQueueItem

      public MailQueueItem getMailQueueItem()
      Returns a MailQueueItem which could be set after sending mail
      Returns:
      the MailQueueItem, otherwise null
    • getUserOrMailbox

      public Persistent getUserOrMailbox()
      Returns:
      a User or MailBox object which has been defined as sender with methods sendPropsFromUser() or sendPropsFormMailBox(); otherwise null is returned
    • getSession

      public Session getSession()
      Returns:
    • setPropsFromMailBox

      public void setPropsFromMailBox(MailBox mb)
      set mailsender properties from mailbox data. Mails can be only put into the mailqueue if they are send by default, mailbox or user properties.
      Parameters:
      mb - - the mailbox which mailadress (and credentials) should be used as sender
    • setPropsFromUser

      public void setPropsFromUser(User u)
      set mailsender properties from mailbox data. Mails can be only put into the mailqueue if they are send by default, mailbox or user properties.
      Parameters:
      u - - the u which mailadress (and mail credentials) should be used as sender
    • setDefaultProps

      public void setDefaultProps()
      set default mailsender properties defined in configuration Mails can be only put into the mailqueue if they are send by default, mailbox or user properties.
    • setDefaultProps

      public void setDefaultProps(MailBox mb)
      Set mailsender properties as defined for a mailbox Mails can be only put into the mailqueue if they are send by default, mailbox or user properties.
    • setDefaultProps

      public void setDefaultProps(Properties props)
    • getMailActionFromConfiguration

      public static MailSender.MailAction getMailActionFromConfiguration()
      Get mail action from configuration
      Returns:
      the mail action
    • activateDebugStream

      public void activateDebugStream()
      Activate logging of this senders session to a Stream. Must be called before construction of the mail session takes place. The contents of the stream can afterwards be obtained by calling getDebugStreamContents().
    • getDebugStreamContents

      public String getDebugStreamContents()
      Get the contents of the debugging stream. Must have been activated via activateDebugStream().
      Returns:
      the contents of the stream or null