Class MailSenderImp

  • All Implemented Interfaces:
    MailSender
    Direct Known Subclasses:
    SmtpClient

    public abstract class MailSenderImp
    extends java.lang.Object
    implements MailSender
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.mail.internet.MimeMessage message  
      protected javax.mail.Session session  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MailSenderImp()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAttachment​(byte[] bytes, java.lang.String filename, java.lang.String type)
      Add an attachment to the email.
      void addAttachment​(byte[] bytes, java.lang.String filename, java.lang.String type, java.lang.String encoding)
      Add an attachment to the email.
      void addAttachment​(Attachment a)
      Add an attachment to the email.
      void addBlindCarbonCopy​(java.lang.String address)
      Add a name to the BCC list.
      void addBlindCarbonCopy​(javax.mail.internet.InternetAddress[] address)
      Add some names to the BCC list.
      void addCarbonCopy​(java.lang.String address)
      Add some names to the CC list.
      void addCarbonCopy​(javax.mail.internet.InternetAddress[] address)
      Add some names to the CC list.
      void addMailHeader​(java.lang.String key, java.lang.String value)
      Add a header to the mail header.
      void addSessionProperty​(java.lang.String key, java.lang.String value)
      Add a property to the set of properties used by the Session.
      void addTo​(java.lang.String address)
      Add some names to the TO list.
      void addTo​(javax.mail.internet.InternetAddress[] address)
      Add some names to the TO list.
      protected void buildContent()
      Build the content of the MimeMessage from the constituent parts.
      void newMessage()
      Create a new message Must be called prior to setting recipient list, mail body etc.
      void removeMailHeader​(java.lang.String key)
      Remove a mail header.
      void removeSessionProperty​(java.lang.String key)
      Remove a property from the set of properties used by the Session.
      void setEncoding​(java.lang.String enc)
      Set the encoding type to use for the message type.
      void setFrom​(java.lang.String from)
      Set the sender.
      void setFrom​(javax.mail.internet.InternetAddress from)
      Set the sender.
      void setMessage​(byte[] bytes)
      Set the message
      void setMessage​(byte[] bytes, java.lang.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 setSubject​(java.lang.String s)
      Set the subject of the email.
      void startSession()
      Start session based on session properties This may be used to initialise the client prior to sending any mail
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • session

        protected javax.mail.Session session
      • message

        protected javax.mail.internet.MimeMessage message
    • Constructor Detail

      • MailSenderImp

        protected MailSenderImp()
    • Method Detail

      • addSessionProperty

        public void addSessionProperty​(java.lang.String key,
                                       java.lang.String value)
        Add a property to the set of properties used by the Session.
        Specified by:
        addSessionProperty in interface MailSender
        Parameters:
        key - the key
        value - the value.
      • removeSessionProperty

        public void removeSessionProperty​(java.lang.String key)
        Remove a property from the set of properties used by the Session.
        Specified by:
        removeSessionProperty in interface MailSender
        Parameters:
        key -
      • startSession

        public void startSession()
                          throws MailException
        Description copied from interface: MailSender
        Start session based on session properties This may be used to initialise the client prior to sending any mail
        Specified by:
        startSession in interface MailSender
        Throws:
        MailException
      • addMailHeader

        public void addMailHeader​(java.lang.String key,
                                  java.lang.String value)
                           throws MailException
        Description copied from interface: MailSender
        Add a header to the mail header.
        Specified by:
        addMailHeader in interface MailSender
        Parameters:
        key - the key
        value - the value.
        Throws:
        MailException
      • addTo

        public void addTo​(javax.mail.internet.InternetAddress[] address)
                   throws MailException
        Description copied from interface: MailSender
        Add some names to the TO list.
        Specified by:
        addTo in interface MailSender
        Parameters:
        address - an array of InternetAddress[] representing email addresses
        Throws:
        MailException - if the addresses could not be parsed.
      • addTo

        public void addTo​(java.lang.String address)
                   throws MailException
        Description copied from interface: MailSender
        Add some names to the TO list.
        Specified by:
        addTo in interface MailSender
        Parameters:
        address - the email address name@company.com
        Throws:
        MailException - if the addresses could not be parsed.
      • addCarbonCopy

        public void addCarbonCopy​(javax.mail.internet.InternetAddress[] address)
                           throws MailException
        Description copied from interface: MailSender
        Add some names to the CC list.
        Specified by:
        addCarbonCopy in interface MailSender
        Parameters:
        address - an array of InternetAddress[] representing email addresses
        Throws:
        MailException - if the addresses could not be parsed.
      • addCarbonCopy

        public void addCarbonCopy​(java.lang.String address)
                           throws MailException
        Description copied from interface: MailSender
        Add some names to the CC list.
        Specified by:
        addCarbonCopy in interface MailSender
        Parameters:
        address - the email address name@company.com
        Throws:
        MailException - if the addresses could not be parsed.
      • addBlindCarbonCopy

        public void addBlindCarbonCopy​(javax.mail.internet.InternetAddress[] address)
                                throws MailException
        Description copied from interface: MailSender
        Add some names to the BCC list.
        Specified by:
        addBlindCarbonCopy in interface MailSender
        Parameters:
        address - an array of InternetAddress[] representing email addresses
        Throws:
        MailException - if the addresses could not be parsed.
      • addBlindCarbonCopy

        public void addBlindCarbonCopy​(java.lang.String address)
                                throws MailException
        Description copied from interface: MailSender
        Add a name to the BCC list.
        Specified by:
        addBlindCarbonCopy in interface MailSender
        Parameters:
        address - email address name@company.com
        Throws:
        MailException - if the addresses could not be parsed.
      • setFrom

        public void setFrom​(java.lang.String from)
                     throws MailException
        Description copied from interface: MailSender
        Set the sender.
        Specified by:
        setFrom in interface MailSender
        Parameters:
        from - email address name@company.com
        Throws:
        MailException - if the addresses could not be parsed.
      • setFrom

        public void setFrom​(javax.mail.internet.InternetAddress from)
                     throws MailException
        Description copied from interface: MailSender
        Set the sender.
        Specified by:
        setFrom in interface MailSender
        Parameters:
        from - InternetAddress container for name@company.com
        Throws:
        MailException - if the addresses could not be parsed.
      • addAttachment

        public void addAttachment​(byte[] bytes,
                                  java.lang.String filename,
                                  java.lang.String type,
                                  java.lang.String encoding)
                           throws MailException
        Description copied from interface: MailSender
        Add an attachment to the email.
        Specified by:
        addAttachment in interface MailSender
        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

        public void addAttachment​(byte[] bytes,
                                  java.lang.String filename,
                                  java.lang.String type)
                           throws MailException
        Description copied from interface: MailSender
        Add an attachment to the email.
        Specified by:
        addAttachment in interface MailSender
        Parameters:
        bytes - the attachment;
        filename - the filename to use for the attachment.
        type - the content type to associate with this attachment
        Throws:
        MailException
      • setMessage

        public void setMessage​(byte[] bytes,
                               java.lang.String contentType)
                        throws MailException
        Description copied from interface: MailSender
        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.
        Specified by:
        setMessage in interface MailSender
        Parameters:
        bytes - the message
        contentType - the content type.
        Throws:
        MailException
        See Also:
        DataContentHandler
      • setEncoding

        public void setEncoding​(java.lang.String enc)
        Description copied from interface: MailSender
        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.

        Specified by:
        setEncoding in interface MailSender
        Parameters:
        enc - the encoding type to use.
      • buildContent

        protected void buildContent()
                             throws MailException
        Build the content of the MimeMessage from the constituent parts.
        Throws:
        MailException