Class Email

    • Field Detail

      • ATTACHMENT_NAME

        protected static final String ATTACHMENT_NAME
        The name for an attachment if not set explicitly. Rather useless.
        See Also:
        Constant Field Values
      • logger

        protected transient Logger logger
        The logger for problems with attachments (rather the corresponding streams).
    • Constructor Detail

      • Email

        @Deprecated(since="15.0.0",
                    forRemoval=true)
        public Email()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use Email(Logger) instead.
        Creates a new email to be built using the corresponding builder methods. Initially the email is empty and cannot be used.
      • Email

        public Email​(Logger logger)
        Creates a new email to be built using the corresponding builder methods. Initially the email is empty and cannot be used.
        Parameters:
        logger - The logger for problems with attachments (rather the corresponding streams).
    • Method Detail

      • getFrom

        public EmailAddress getFrom()
        Gets the address of the sender. This may be null when using a MailService for sending this mail. In this case the MailService will set a default sending address.
        Returns:
        The address of the sender or null.
      • getReplyTo

        public EmailAddress getReplyTo()
        Gets the address to which to reply to (in case this differs from the sender) or null.
        Returns:
        The address to which to reply to (in case this differs from the sender) or null.
      • getBounceTo

        public EmailAddress getBounceTo()
        Gets the address to which to send problems that occur on the way of the mail to its recipient or null.
        Returns:
        The address to which to send problems that occur on the way of the mail to its recipient or null.
      • getTo

        public List<EmailAddress> getTo()
        Gets the addresses to which to send the mail. This has to contain at least one valid address.
        Returns:
        The addresses to which to send the mail.
      • getCc

        public List<EmailAddress> getCc()
        Gets the addresses to which to send a copy of the mail or an empty list.
        Returns:
        The addresses to which to send a copy of the mail or an empty list.
      • getBcc

        public List<EmailAddress> getBcc()
        Gets the addresses to which to send a copy of the mail unaware of the other recipients or an empty list.
        Returns:
        The addresses to which to send a copy of the mail unaware of the other recipients.
      • getSubject

        public String getSubject()
        Gets the subject of the mail. This has to be set before sending the mail.
        Returns:
        The subject of the mail.
      • getText

        public String getText()
        Gets the text content of the mail, i. e. the text mail body. This has to be set before sending the mail.
        Returns:
        The text content of the mail, i. e. the text mail body. This has to be set before sending the mail.
      • isHtml

        public boolean isHtml()
        Gets whether the text content of the mail is HTML (instead of plain text) and should be formatted appropriately.
        Returns:
        Whether the text content of the mail is HTML (instead of plain text) and should be formatted appropriately.
      • getPriority

        public EmailPriority getPriority()
        Gets the priority of this mail or null.
        Returns:
        The priority of this mail or null.
      • getAttachments

        public List<SerialisableAttachment> getAttachments()
        Gets the files attached to the mail or an empty list.
        Returns:
        The files attached to the mail or an empty list.
      • getHeaders

        public Map<String,​String> getHeaders()
        Gets additional headers of the mail or an empty map./
        Returns:
        Additional headers of the mail or an empty map.
      • from

        public Email from​(String address)
        Sets the address of the sender.
        Parameters:
        address - The address of the sender.
        Returns:
        This Email.
      • from

        public Email from​(String name,
                          String address)
        Sets the address and the name of the sender.
        Parameters:
        name - The name of the sender.
        address - The address of the sender.
        Returns:
        This Email.
      • clearFrom

        public Email clearFrom()
        Removes the address of the sender.
        Returns:
        This Email.
      • replyTo

        public Email replyTo​(String address)
        Sets the address to which to reply to (in case this differs from the sender).
        Parameters:
        address - The address to which to reply to.
        Returns:
        This Email.
      • replyTo

        public Email replyTo​(String name,
                             String address)
        The address to which to reply to (in case this differs from the sender).
        Parameters:
        name - The name to which to reply to.
        address - The address to which to reply to.
        Returns:
        This Email.
      • clearReplyTo

        public Email clearReplyTo()
        Removes the address to which to reply to.
        Returns:
        This Email.
      • bounceTo

        public Email bounceTo​(String address)
        Sets the address to which to send problems that occur on the way of the mail to its recipient.
        Parameters:
        address - The address to which to send problems that occur on the way of the mail to its recipient.
        Returns:
        This Email.
      • bounceTo

        public Email bounceTo​(String name,
                              String address)
        Sets the address to which to send problems that occur on the way of the mail to its recipient.
        Parameters:
        name - The name to which to send problems that occur on the way of the mail to its recipient.
        address - The address to which to send problems that occur on the way of the mail to its recipient.
        Returns:
        This Email.
      • clearBounceTo

        public Email clearBounceTo()
        Removes the address to which to send problems that occur on the way of the mail to its recipient.
        Returns:
        This Email.
      • to

        public Email to​(String address)
        Sets an address to which to send the mail. At least one address has to be set before sending the mail.
        Parameters:
        address - An address to which to send the mail.
        Returns:
        This Email.
      • to

        public Email to​(String name,
                        String address)
        Sets an address to which to send the mail. At least one address has to be set before sending the mail.
        Parameters:
        name - A name to which to send the mail.
        address - An address to which to send the mail.
        Returns:
        This Email.
      • clearTo

        public Email clearTo()
        Removes all addresses to which to send the mail.
        Returns:
        This Email.
      • cc

        public Email cc​(String address)
        Sets an address to which to send a copy of the mail.
        Parameters:
        address - An address to which to send a copy of the mail.
        Returns:
        This Email.
      • cc

        public Email cc​(String name,
                        String address)
        Sets an address to which to send a copy of the mail.
        Parameters:
        name - A name to which to send a copy of the mail.
        address - An address to which to send a copy of the mail.
        Returns:
        This Email.
      • clearCc

        public Email clearCc()
        Removes all addresses to which to send copies of the mail.
        Returns:
        This Email.
      • bcc

        public Email bcc​(String address)
        Sets an address to which to send a copy of the mail unaware of the other recipients.
        Parameters:
        address - An address to which to send a copy of the mail unaware of the other recipients.
        Returns:
        This Email.
      • bcc

        public Email bcc​(String name,
                         String address)
        Sets an address to which to send a copy of the mail unaware of the other recipients.
        Parameters:
        name - A name to which to send a copy of the mail unaware of the other recipients.
        address - An address to which to send a copy of the mail unaware of the other recipients.
        Returns:
        This Email.
      • clearBcc

        public Email clearBcc()
        Removes all addresses to which to send copies of the mail unaware of the other recipients.
        Returns:
        This Email.
      • subject

        public Email subject​(String subj)
        Sets the subject of the mail. This has to be set before sending the mail.
        Parameters:
        subj - The subject of the mail.
        Returns:
        This Email.
      • text

        public Email text​(String txt)
        Sets the text content of the mail, i. e. the text mail body. This has to be set before sending the mail.
        Parameters:
        txt - The text content of the mail, i. e. the text mail body. This has to be set before sending the mail.
        Returns:
        This Email.
      • html

        public Email html​(String htm)
        Sets the content of the mail as HTML formatted text. This replaces text(String). This has to be set before sending the mail.
        Parameters:
        htm - The HTML formatted text content of the mail, i. e. the text mail body. This has to be set before sending the mail.
        Returns:
        This Email.
      • priority

        public Email priority​(int intPrio)
        Sets the priority.
        Parameters:
        intPrio - The integer value of the priority to set.
        Returns:
        This Email.
      • priority

        public Email priority​(String strPrio)
        Sets the priority.
        Parameters:
        strPrio - The string value of the priority to set (the same name as the constants with space instead of underscore and case-insensitive).
        Returns:
        This Email.
      • priority

        public Email priority​(EmailPriority prio)
        Sets the priority.
        Parameters:
        prio - The priority to set.
        Returns:
        This Email.
      • clearPriority

        public Email clearPriority()
        Removes the priority.
        Returns:
        This Email.
      • attachment

        public Email attachment​(SerialisableAttachment att)
        Adds the designated attachment to this mail.
        Parameters:
        att - The attachment.
        Returns:
        This Email.
      • attachment

        public Email attachment​(String fileName,
                                UDTValue attData,
                                boolean embed)
        Adds the content of the designated UDT value as attachment to this mail. If the UDT name of the designated contains a /, the name will be assumed to be a valid content type and thus used appropriately. Otherwise application/octet-stream will be used as content type.
        Parameters:
        fileName - The file name of the attachment. This must not be null nor blank.
        attData - The actual content. The caller is responsible for closing.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
      • attachment

        public Email attachment​(String fileName,
                                String contentType,
                                UDTValue attData,
                                boolean embed)
        Adds the content of the designated UDT value as attachment to this mail.
        Parameters:
        fileName - The file name of the attachment. This must not be null nor blank.
        contentType - The content type of the file. If this is null, application/octet-stream will be used.
        attData - The actual content. The caller is responsible for closing.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
      • attachment

        public Email attachment​(String fileName,
                                String contentType,
                                byte[] attData,
                                boolean embed)
        Adds the designated content as attachment to this mail.
        Parameters:
        fileName - The file name of the attachment. This must not be null nor blank.
        contentType - The content type of the file. If this is null, application/octet-stream will be used.
        attData - The actual content.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
      • attachment

        public Email attachment​(URL attSource,
                                boolean embed)
        Adds the content of the designated URL as attachment to this mail.
        Parameters:
        attSource - The URL used as data source, providing name, the content type and the actual attachment content.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
      • attachment

        public Email attachment​(String fileName,
                                String contentType,
                                URL attSource,
                                boolean embed)
        Adds the content of the designated URL as attachment to this mail.
        Parameters:
        fileName - The file name of the attachment. If this is null or blank, default name will be used.
        contentType - The content type of the attachment. If this is null, application/octet-stream will be used.
        attSource - The URL from which to retrieve the content.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
      • attachment

        public Email attachment​(URI attSource,
                                boolean embed)
                         throws MalformedURLException
        Adds the content of the designated URI as attachment to this mail.
        Parameters:
        attSource - The URI used as data source, providing name, the content type and the actual attachment content.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
        Throws:
        MalformedURLException - If there are problems converting the designated URI to a URL, a MalFormedURLException will be thrown.
      • attachment

        public Email attachment​(String fileName,
                                String contentType,
                                URI attSource,
                                boolean embed)
                         throws MalformedURLException
        Adds the content of the designated URI as attachment to this mail.
        Parameters:
        fileName - The file name of the attachment. If this is null or blank, default name will be used.
        contentType - The content type of the attachment. If this is null, application/octet-stream will be used.
        attSource - The URI from which to retrieve the content.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
        Throws:
        MalformedURLException - If there are problems converting the designated URI to a URL, a MalFormedURLException will be thrown.
      • attachment

        public Email attachment​(javax.activation.DataSource attSource,
                                boolean embed)
        Adds the designated attachment to this mail.
        Parameters:
        attSource - The data source providing name, the content type and the actual attachment content.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
      • attachment

        public Email attachment​(String fileName,
                                String contentType,
                                javax.activation.DataSource attSource,
                                boolean embed)
        Adds the designated attachment to this mail.
        Parameters:
        fileName - The file name of the attachment. If this is null or blank the name of the designated data source will be used. If this is also null or blank, default name will be used.
        contentType - The content type of the attachment. If this is not null, it will override the content type of the designated data source.
        attSource - The data source providing the actual attachment content.
        embed - Whether to embed this attachment, i. e. hiding it from the list of attachments.
        Returns:
        This Email.
      • clearAttachments

        public Email clearAttachments()
        Removes all attachments from this mail.
        Returns:
        This Email.
      • header

        public Email header​(String name,
                            String value)
        Adds the designated key-value-pair as additional header of this mail.
        Parameters:
        name - The name of the additional header.
        value - The value of the additional header. This may be null.
        Returns:
        This Email.
      • clearHeaders

        public Email clearHeaders()
        Removes all additional headers from this mail.
        Returns:
        This Email.