Interface MessageBuilder

  • All Known Implementing Classes:
    SimpleMessageBuilder

    @ProviderType
    public interface MessageBuilder
    Builder for MIME messages.
    See Also:
    MimeMessage
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      @NotNull MessageBuilder attachment​(byte @NotNull [] content, @NotNull String type, @NotNull String filename)
      Attaches the given content to the message.
      @NotNull MessageBuilder attachment​(byte @NotNull [] content, @NotNull String type, @NotNull String filename, @Nullable Collection<jakarta.mail.Header> headers)
      Attaches the given content with headers to the message.
      @NotNull MessageBuilder bcc​(@NotNull jakarta.mail.internet.InternetAddress bcc)
      Adds the given address to the list of blind carbon copy (bcc) recipients.
      @NotNull MessageBuilder bcc​(@NotNull jakarta.mail.internet.InternetAddress[] addresses)
      Adds the given addresses to the list of blind carbon copy (bcc) recipients.
      @NotNull MessageBuilder bcc​(@NotNull String address)
      Creates a new InternetAddress from given address and adds it to the list of blind carbon copy (bcc) recipients.
      @NotNull MessageBuilder bcc​(@NotNull String[] addresses)
      Creates new InternetAddresses from given addresses and adds them to the list of blind carbon copy (bcc) recipients.
      @NotNull MessageBuilder bcc​(@NotNull String address, String name)
      Creates a new InternetAddress from given address and name and adds it to the list of blind carbon copy (bcc) recipients.
      @NotNull MessageBuilder bcc​(@NotNull Collection<String> addresses)
      Creates new InternetAddresses from given addresses and adds them to the list of blind carbon copy (bcc) recipients.
      @NotNull jakarta.mail.internet.MimeMessage build()
      Builds the MIME message with the given input.
      @NotNull MessageBuilder cc​(@NotNull jakarta.mail.internet.InternetAddress cc)
      Adds the given address to the list of carbon copy (cc) recipients.
      @NotNull MessageBuilder cc​(@NotNull jakarta.mail.internet.InternetAddress[] addresses)
      Adds the given addresses to the list of carbon copy (cc) recipients.
      @NotNull MessageBuilder cc​(@NotNull String address)
      Creates a new InternetAddress from given address and adds it to the list of carbon copy (cc) recipients.
      @NotNull MessageBuilder cc​(@NotNull String[] addresses)
      Creates new InternetAddresses from given addresses and adds them to the list of carbon copy (cc) recipients.
      @NotNull MessageBuilder cc​(@NotNull String address, @NotNull String name)
      Creates a new InternetAddress from given address and name and adds it to the list of carbon copy (cc) recipients.
      @NotNull MessageBuilder cc​(@NotNull Collection<String> addresses)
      Creates new InternetAddresses from given addresses and adds them to the list of carbon copy (cc) recipients.
      @NotNull MessageBuilder from​(@NotNull jakarta.mail.internet.InternetAddress from)
      Sets the given address for the RFC 822 From header field.
      @NotNull MessageBuilder from​(@NotNull String address)
      Creates a new InternetAddress from given address and sets it for the RFC 822 From header field.
      @NotNull MessageBuilder from​(@NotNull String address, @NotNull String name)
      Creates a new InternetAddress from given address and name and sets it for the RFC 822 From header field.
      @NotNull MessageBuilder header​(@NotNull String name, @Nullable String value)
      Creates a new header from given name and value and adds it to the list of headers.
      @NotNull MessageBuilder headers​(@NotNull Collection<jakarta.mail.Header> headers)
      Adds the given headers to the list of headers.
      @NotNull MessageBuilder html​(@NotNull String html)
      Sets the HTML content.
      @NotNull MessageBuilder inline​(byte @NotNull [] content, @NotNull String type, @NotNull String cid)
      Inlines the given content into the message.
      @NotNull MessageBuilder inline​(byte @NotNull [] content, @NotNull String type, @NotNull String cid, @Nullable Collection<jakarta.mail.Header> headers)
      Inlines the given content with headers into the message.
      @NotNull MessageBuilder replyTo​(@NotNull jakarta.mail.internet.InternetAddress replyTo)
      Adds the given address to the list of addresses for the RFC 822 Reply-To header field.
      @NotNull MessageBuilder replyTo​(@NotNull jakarta.mail.internet.InternetAddress[] addresses)
      Adds the given addresses to the list of addresses for the RFC 822 Reply-To header field.
      @NotNull MessageBuilder replyTo​(@NotNull String address)
      Creates a new InternetAddress from given address and adds it to the list of addresses for the RFC 822 Reply-To header field.
      @NotNull MessageBuilder replyTo​(@NotNull String[] addresses)
      Creates new InternetAddresses from given addresses and adds them to the list of addresses for the RFC 822 Reply-To header field.
      @NotNull MessageBuilder replyTo​(@NotNull String address, String name)
      Creates a new InternetAddress from given address and name and adds it to the list of addresses for the RFC 822 Reply-To header field.
      @NotNull MessageBuilder replyTo​(@NotNull Collection<String> addresses)
      Creates new InternetAddresses from given addresses and adds them to the list of addresses for the RFC 822 Reply-To header field.
      @NotNull MessageBuilder subject​(@NotNull String subject)
      Sets the given subject into the Subject header field.
      @NotNull MessageBuilder text​(@NotNull String text)
      Sets the plain text content.
      @NotNull MessageBuilder to​(@NotNull jakarta.mail.internet.InternetAddress to)
      Adds the given address to the list of primary (to) recipients.
      @NotNull MessageBuilder to​(@NotNull jakarta.mail.internet.InternetAddress[] addresses)
      Adds the given addresses to the list of primary (to) recipients.
      @NotNull MessageBuilder to​(@NotNull String address)
      Creates a new InternetAddress from given address and adds it to the list of primary (to) recipients.
      @NotNull MessageBuilder to​(@NotNull String[] addresses)
      Creates new InternetAddresses from given addresses and adds them to the list of primary (to) recipients.
      @NotNull MessageBuilder to​(@NotNull String address, @NotNull String name)
      Creates a new InternetAddress from given address and name and adds it to the list of primary (to) recipients.
      @NotNull MessageBuilder to​(@NotNull Collection<String> addresses)
      Creates new InternetAddresses from given addresses and adds them to the list of primary (to) recipients.
    • Method Detail

      • header

        @NotNull
        @NotNull MessageBuilder header​(@NotNull
                                       @NotNull String name,
                                       @Nullable
                                       @Nullable String value)
        Creates a new header from given name and value and adds it to the list of headers.
        Parameters:
        name - the name of the header
        value - the value of the header
        Returns:
        the message builder
        See Also:
        Header, InternetHeaders
      • headers

        @NotNull
        @NotNull MessageBuilder headers​(@NotNull
                                        @NotNull Collection<jakarta.mail.Header> headers)
        Adds the given headers to the list of headers.
        Parameters:
        headers - the headers to add
        Returns:
        the message builder
        See Also:
        Header, InternetHeaders
      • from

        @NotNull
        @NotNull MessageBuilder from​(@NotNull
                                     @NotNull jakarta.mail.internet.InternetAddress from)
        Sets the given address for the RFC 822 From header field.
        Parameters:
        from - the address
        Returns:
        the message builder
        See Also:
        MimeMessage.setFrom(Address)
      • from

        @NotNull
        @NotNull MessageBuilder from​(@NotNull
                                     @NotNull String address)
                              throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and sets it for the RFC 822 From header field.
        Parameters:
        address - the address
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setFrom(Address)
      • from

        @NotNull
        @NotNull MessageBuilder from​(@NotNull
                                     @NotNull String address,
                                     @NotNull
                                     @NotNull String name)
                              throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and name and sets it for the RFC 822 From header field.
        Parameters:
        address - the address
        name - the (personal) name
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setFrom(Address)
      • to

        @NotNull
        @NotNull MessageBuilder to​(@NotNull
                                   @NotNull jakarta.mail.internet.InternetAddress to)
        Adds the given address to the list of primary (to) recipients.
        Parameters:
        to - the address
        Returns:
        the message builder
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.TO
      • to

        @NotNull
        @NotNull MessageBuilder to​(@NotNull
                                   @NotNull String address)
                            throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and adds it to the list of primary (to) recipients.
        Parameters:
        address - the address
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.TO
      • to

        @NotNull
        @NotNull MessageBuilder to​(@NotNull
                                   @NotNull String address,
                                   @NotNull
                                   @NotNull String name)
                            throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and name and adds it to the list of primary (to) recipients.
        Parameters:
        address - the address
        name - the (personal) name
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.TO
      • to

        @NotNull
        @NotNull MessageBuilder to​(@NotNull
                                   @NotNull jakarta.mail.internet.InternetAddress[] addresses)
        Adds the given addresses to the list of primary (to) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.TO
      • to

        @NotNull
        @NotNull MessageBuilder to​(@NotNull
                                   @NotNull String[] addresses)
                            throws jakarta.mail.internet.AddressException
        Creates new InternetAddresses from given addresses and adds them to the list of primary (to) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address strings fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.TO
      • to

        @NotNull
        @NotNull MessageBuilder to​(@NotNull
                                   @NotNull Collection<String> addresses)
                            throws jakarta.mail.internet.AddressException
        Creates new InternetAddresses from given addresses and adds them to the list of primary (to) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address strings fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.TO
      • cc

        @NotNull
        @NotNull MessageBuilder cc​(@NotNull
                                   @NotNull jakarta.mail.internet.InternetAddress cc)
        Adds the given address to the list of carbon copy (cc) recipients.
        Parameters:
        cc - the address
        Returns:
        the message builder
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.CC
      • cc

        @NotNull
        @NotNull MessageBuilder cc​(@NotNull
                                   @NotNull String address)
                            throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and adds it to the list of carbon copy (cc) recipients.
        Parameters:
        address - the address
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.CC
      • cc

        @NotNull
        @NotNull MessageBuilder cc​(@NotNull
                                   @NotNull String address,
                                   @NotNull
                                   @NotNull String name)
                            throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and name and adds it to the list of carbon copy (cc) recipients.
        Parameters:
        address - the address
        name - the (personal) name
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.CC
      • cc

        @NotNull
        @NotNull MessageBuilder cc​(@NotNull
                                   @NotNull jakarta.mail.internet.InternetAddress[] addresses)
        Adds the given addresses to the list of carbon copy (cc) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.CC
      • cc

        @NotNull
        @NotNull MessageBuilder cc​(@NotNull
                                   @NotNull String[] addresses)
                            throws jakarta.mail.internet.AddressException
        Creates new InternetAddresses from given addresses and adds them to the list of carbon copy (cc) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address strings fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.CC
      • cc

        @NotNull
        @NotNull MessageBuilder cc​(@NotNull
                                   @NotNull Collection<String> addresses)
                            throws jakarta.mail.internet.AddressException
        Creates new InternetAddresses from given addresses and adds them to the list of carbon copy (cc) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address strings fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.CC
      • bcc

        @NotNull
        @NotNull MessageBuilder bcc​(@NotNull
                                    @NotNull jakarta.mail.internet.InternetAddress bcc)
        Adds the given address to the list of blind carbon copy (bcc) recipients.
        Parameters:
        bcc - the address
        Returns:
        the message builder
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.BCC
      • bcc

        @NotNull
        @NotNull MessageBuilder bcc​(@NotNull
                                    @NotNull String address)
                             throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and adds it to the list of blind carbon copy (bcc) recipients.
        Parameters:
        address - the address
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.BCC
      • bcc

        @NotNull
        @NotNull MessageBuilder bcc​(@NotNull
                                    @NotNull String address,
                                    String name)
                             throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and name and adds it to the list of blind carbon copy (bcc) recipients.
        Parameters:
        address - the address
        name - the (personal) name
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.BCC
      • bcc

        @NotNull
        @NotNull MessageBuilder bcc​(@NotNull
                                    @NotNull jakarta.mail.internet.InternetAddress[] addresses)
        Adds the given addresses to the list of blind carbon copy (bcc) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.BCC
      • bcc

        @NotNull
        @NotNull MessageBuilder bcc​(@NotNull
                                    @NotNull String[] addresses)
                             throws jakarta.mail.internet.AddressException
        Creates new InternetAddresses from given addresses and adds them to the list of blind carbon copy (bcc) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address strings fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.BCC
      • bcc

        @NotNull
        @NotNull MessageBuilder bcc​(@NotNull
                                    @NotNull Collection<String> addresses)
                             throws jakarta.mail.internet.AddressException
        Creates new InternetAddresses from given addresses and adds them to the list of blind carbon copy (bcc) recipients.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address strings fails
        See Also:
        MimeMessage.setRecipients(RecipientType, Address[]), Message.RecipientType.BCC
      • replyTo

        @NotNull
        @NotNull MessageBuilder replyTo​(@NotNull
                                        @NotNull jakarta.mail.internet.InternetAddress replyTo)
        Adds the given address to the list of addresses for the RFC 822 Reply-To header field.
        Parameters:
        replyTo - the address
        Returns:
        the message builder
        See Also:
        MimeMessage.setReplyTo(Address[])
      • replyTo

        @NotNull
        @NotNull MessageBuilder replyTo​(@NotNull
                                        @NotNull String address)
                                 throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and adds it to the list of addresses for the RFC 822 Reply-To header field.
        Parameters:
        address - the address
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setReplyTo(Address[])
      • replyTo

        @NotNull
        @NotNull MessageBuilder replyTo​(@NotNull
                                        @NotNull String address,
                                        String name)
                                 throws jakarta.mail.internet.AddressException
        Creates a new InternetAddress from given address and name and adds it to the list of addresses for the RFC 822 Reply-To header field.
        Parameters:
        address - the address
        name - the (personal) name
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address string fails
        See Also:
        MimeMessage.setReplyTo(Address[])
      • replyTo

        @NotNull
        @NotNull MessageBuilder replyTo​(@NotNull
                                        @NotNull jakarta.mail.internet.InternetAddress[] addresses)
        Adds the given addresses to the list of addresses for the RFC 822 Reply-To header field.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        See Also:
        MimeMessage.setReplyTo(Address[])
      • replyTo

        @NotNull
        @NotNull MessageBuilder replyTo​(@NotNull
                                        @NotNull String[] addresses)
                                 throws jakarta.mail.internet.AddressException
        Creates new InternetAddresses from given addresses and adds them to the list of addresses for the RFC 822 Reply-To header field.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address strings fails
        See Also:
        MimeMessage.setReplyTo(Address[])
      • replyTo

        @NotNull
        @NotNull MessageBuilder replyTo​(@NotNull
                                        @NotNull Collection<String> addresses)
                                 throws jakarta.mail.internet.AddressException
        Creates new InternetAddresses from given addresses and adds them to the list of addresses for the RFC 822 Reply-To header field.
        Parameters:
        addresses - the addresses
        Returns:
        the message builder
        Throws:
        jakarta.mail.internet.AddressException - if creating an InternetAddress from given address strings fails
        See Also:
        MimeMessage.setReplyTo(Address[])
      • subject

        @NotNull
        @NotNull MessageBuilder subject​(@NotNull
                                        @NotNull String subject)
        Sets the given subject into the Subject header field.
        Parameters:
        subject - the subject of the message
        Returns:
        the message builder
        See Also:
        MimeMessage.setSubject(String)
      • text

        @NotNull
        @NotNull MessageBuilder text​(@NotNull
                                     @NotNull String text)
        Sets the plain text content.
        Parameters:
        text - the plain text content
        Returns:
        the message builder
        See Also:
        MimeMessage.setText(String, String), MimeBodyPart.setContent(Object, String)
      • html

        @NotNull
        @NotNull MessageBuilder html​(@NotNull
                                     @NotNull String html)
        Sets the HTML content.
        Parameters:
        html - the HTML content
        Returns:
        the message builder
        See Also:
        MimeBodyPart.setContent(Object, String)
      • attachment

        @NotNull
        @NotNull MessageBuilder attachment​(byte @NotNull [] content,
                                           @NotNull
                                           @NotNull String type,
                                           @NotNull
                                           @NotNull String filename)
        Attaches the given content to the message.
        Parameters:
        content - the content to attach
        type - the type of the content (content/media/MIME type)
        filename - the filename of the attachment
        Returns:
        the message builder
        See Also:
        Part.ATTACHMENT
      • attachment

        @NotNull
        @NotNull MessageBuilder attachment​(byte @NotNull [] content,
                                           @NotNull
                                           @NotNull String type,
                                           @NotNull
                                           @NotNull String filename,
                                           @Nullable
                                           @Nullable Collection<jakarta.mail.Header> headers)
        Attaches the given content with headers to the message.
        Parameters:
        content - the content to attach
        type - the type of the content (content/media/MIME type)
        filename - the filename of the attachment
        headers - the headers for the content
        Returns:
        the message builder
        See Also:
        Part.ATTACHMENT
      • inline

        @NotNull
        @NotNull MessageBuilder inline​(byte @NotNull [] content,
                                       @NotNull
                                       @NotNull String type,
                                       @NotNull
                                       @NotNull String cid)
        Inlines the given content into the message.
        Parameters:
        content - the content to inline
        type - the type of the content (content/media/MIME type)
        cid - the content identifier (Content-ID)
        Returns:
        the message builder
        See Also:
        Part.INLINE
      • inline

        @NotNull
        @NotNull MessageBuilder inline​(byte @NotNull [] content,
                                       @NotNull
                                       @NotNull String type,
                                       @NotNull
                                       @NotNull String cid,
                                       @Nullable
                                       @Nullable Collection<jakarta.mail.Header> headers)
        Inlines the given content with headers into the message.
        Parameters:
        content - the content to inline
        type - the type of the content (content/media/MIME type)
        cid - the content identifier (Content-ID)
        headers - the headers for the content
        Returns:
        the message builder
        See Also:
        Part.INLINE
      • build

        @NotNull
        @NotNull jakarta.mail.internet.MimeMessage build()
                                                  throws jakarta.mail.MessagingException
        Builds the MIME message with the given input.
        Returns:
        the built message
        Throws:
        jakarta.mail.MessagingException - if building message fails