Interface MailSender

All Known Implementing Classes:
MailSenderImp, SmtpClient

public interface MailSender
An interface for an email sender client.

The javax.mail MimeMessage and Session objects are used at least to hold message data although the client implementation may not necessarily use javax.mail system, in which case a conversion will be required to store data in the MimeMessage object.

Expected usage:- construct client sender object add/remove session properties start session call newMessage method call setFrom, addTo/cc/Bcc, setSubject, setMessage, addAttachments as required call send

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAttachment(byte[] bytes, String filename, String type)
    Add an attachment to the email.
    void
    addAttachment(byte[] bytes, String filename, String type, String encoding)
    Add an attachment to the email.
    void
    Add an attachment to the email.
    void
    Add a name to the BCC list.
    void
    addBlindCarbonCopy(javax.mail.internet.InternetAddress[] bcc)
    Add some names to the BCC list.
    void
    Add some names to the CC list.
    void
    addCarbonCopy(javax.mail.internet.InternetAddress[] cc)
    Add some names to the CC list.
    void
    Add a header to the mail header.
    void
    Add a property to the set of properties used by the SMTP Session.
    void
    addTo(String address)
    Add some names to the TO list.
    void
    addTo(javax.mail.internet.InternetAddress[] address)
    Add some names to the TO list.
    void
    Create a new message Must be called prior to setting recipient list, mail body etc.
    void
    Remove a mail header.
    void
    Remove a property from the set of properties used by the SMTP Session.
    void
    Send the email.
    void
    Set the encoding type to use for the message type.
    void
    Set the sender.
    void
    setFrom(javax.mail.internet.InternetAddress from)
    Set the sender.
    void
    setMessage(byte[] bytes)
    Set the message
    void
    setMessage(byte[] bytes, String contentType)
    Set the message and content type Content type maybe an arbitary string such as application/edi-x12, although if an appropriate DataContentHandler is not installed, then the results can be undefined.
    void
    Set the subject of the email.
    void
    Start session based on session properties This may be used to initialise the client prior to sending any mail
  • Method Details

    • addSessionProperty

      void addSessionProperty(String key, String value)
      Add a property to the set of properties used by the SMTP Session.
      Parameters:
      key - the key
      value - the value.
    • removeSessionProperty

      void removeSessionProperty(String key)
      Remove a property from the set of properties used by the SMTP Session.
      Parameters:
      key - the key
    • startSession

      void startSession() throws MailException
      Start session based on session properties This may be used to initialise the client prior to sending any mail
      Throws:
      MailException
    • newMessage

      void newMessage() throws MailException
      Create a new message Must be called prior to setting recipient list, mail body etc.
      Throws:
      MailException
    • addMailHeader

      void addMailHeader(String key, String value) throws MailException
      Add a header to the mail header.
      Parameters:
      key - the key
      value - the value.
      Throws:
      MailException
    • removeMailHeader

      void removeMailHeader(String key) throws MailException
      Remove a mail header.
      Parameters:
      key - the key
      Throws:
      MailException
    • addTo

      void addTo(javax.mail.internet.InternetAddress[] address) throws MailException
      Add some names to the TO list.
      Parameters:
      address - an array of InternetAddress[] representing email addresses
      Throws:
      MailException - if the addresses could not be parsed.
    • addTo

      void addTo(String address) throws MailException
      Add some names to the TO list.
      Parameters:
      address - the email address name@company.com
      Throws:
      MailException - if the addresses could not be parsed.
    • addCarbonCopy

      void addCarbonCopy(javax.mail.internet.InternetAddress[] cc) throws MailException
      Add some names to the CC list.
      Parameters:
      cc - an array of InternetAddress[] representing email addresses
      Throws:
      MailException - if the addresses could not be parsed.
    • addCarbonCopy

      void addCarbonCopy(String cc) throws MailException
      Add some names to the CC list.
      Parameters:
      cc - the email address name@company.com
      Throws:
      MailException - if the addresses could not be parsed.
    • addBlindCarbonCopy

      void addBlindCarbonCopy(javax.mail.internet.InternetAddress[] bcc) throws MailException
      Add some names to the BCC list.
      Parameters:
      bcc - an array of InternetAddress[] representing email addresses
      Throws:
      MailException - if the addresses could not be parsed.
    • addBlindCarbonCopy

      void addBlindCarbonCopy(String bcc) throws MailException
      Add a name to the BCC list.
      Parameters:
      bcc - email address name@company.com
      Throws:
      MailException - if the addresses could not be parsed.
    • setFrom

      void setFrom(String from) throws MailException
      Set the sender.
      Parameters:
      from - email address name@company.com
      Throws:
      MailException - if the addresses could not be parsed.
    • setFrom

      void setFrom(javax.mail.internet.InternetAddress from) throws MailException
      Set the sender.
      Parameters:
      from - InternetAddress container for name@company.com
      Throws:
      MailException - if the addresses could not be parsed.
    • setSubject

      void setSubject(String s) throws MailException
      Set the subject of the email.
      Parameters:
      s - the subject.
      Throws:
      MailException
    • addAttachment

      void addAttachment(byte[] bytes, String filename, String type, String encoding) throws MailException
      Add an attachment to the email.
      Parameters:
      bytes - the attachment;
      filename - the filename to use for the attachment.
      type - the content type to associate with this attachment
      encoding - of the mime body part for this attachment
      Throws:
      MailException
    • addAttachment

      void addAttachment(byte[] bytes, String filename, String type) throws MailException
      Add an attachment to the email.
      Parameters:
      bytes - the attachment;
      filename - the filename to use for the attachment.
      type - the content type to associate with this attachment
      Throws:
      MailException
    • addAttachment

      void addAttachment(Attachment attachment) throws MailException
      Add an attachment to the email.
      Parameters:
      attachment - object;
      Throws:
      MailException
    • setMessage

      void setMessage(byte[] bytes, String contentType) throws MailException
      Set the message and content type Content type maybe an arbitary string such as application/edi-x12, although if an appropriate DataContentHandler is not installed, then the results can be undefined.
      Parameters:
      bytes - the message
      contentType - the content type.
      Throws:
      MailException
      See Also:
      • DataContentHandler
    • setMessage

      void setMessage(byte[] bytes) throws MailException
      Set the message
      Parameters:
      bytes - the message;
      Throws:
      MailException
    • setEncoding

      void setEncoding(String enc)
      Set the encoding type to use for the message type.

      Valid types of encoding are those defined in RFC2045. They include "base64", "quoted-printable", "7bit", "8bit" and "binary". In addition, "uuencode" is also supported.

      Parameters:
      enc - the encoding type to use.
    • send

      void send() throws MailException
      Send the email.
      Throws:
      MailException - wrapping any underlying exception