Interface MailMessage

All Known Implementing Classes:
MailMessageImpl

public interface MailMessage
The MailMessage interface provides methods for creating and managing email messages. It includes methods to set and get various email attributes such as sender, recipients, subject, and date, as well as methods to send and save the message.
Author:
Besmir Beqiri
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a File as an attachment to this message.
    void
    Adds a File as an attachment to this message with the given content ID.
    void
    addAttachment(File file, String contentType, String encoding)
    Adds a File as an attachment to this message with the given content type and encoding.
    void
    addBcc(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Add these addresses to the existing "Bcc" attribute.
    void
    addCc(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Add these addresses to the existing "Cc" attribute.
    void
    addFrom(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Add these addresses to the existing "From" attribute.
    void
    addTo(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Add these addresses to the existing "To" attribute.
    static @NotNull MailMessage
    create(MailClient mailClient)
    Creates a new MailMessage instance using the provided MailClient.
    org.eclipse.collections.api.list.ImmutableList<String>
    Get all the recipients of this message.
    org.eclipse.collections.api.list.ImmutableList<String>
    Return the "Bcc" attribute addresses.
    org.eclipse.collections.api.list.ImmutableList<String>
    Return the "Cc" attribute addresses.
    org.eclipse.collections.api.list.ImmutableList<String>
    Returns the "From" attribute addresses.
    Get the date this message was received.
    org.eclipse.collections.api.list.ImmutableList<String>
    Get the addresses to which replies should be directed.
    Get the date this message was sent.
    Get the subject of this message.
    org.eclipse.collections.api.list.ImmutableList<String>
    Returns the "To" attribute addresses.
    Save any changes made to this message into the message-store when the containing folder is closed, if the message is contained in a folder.
    Send a message.
    send(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Send the message to the specified addresses, ignoring any recipients specified in the message itself.
    void
    setBcc(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Set the "Bcc" attribute addresses in this message.
    void
    setCc(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Set the "Cc" attribute addresses in this message.
    void
    setFrom(String address)
    Set the "From" attribute address in this message.
    void
    setHtml(String htmlText)
    A convenience method that sets the given String as this part's content with a MIME type of "text/html".
    void
    setReplyTo(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Set the addresses to which replies should be directed.
    void
    Set the sent date of this message.
    void
    setSubject(String subject)
    Set the subject of this message.
    void
    A convenience method that sets the given String as this part's content with a MIME type of "text/plain".
    void
    setTo(String address)
    Set the "To" attribute address in this message.
    void
    setTo(org.eclipse.collections.api.list.ImmutableList<String> addresses)
    Set the "To" attribute addresses in this message.
  • Method Details

    • create

      @NotNull static @NotNull MailMessage create(MailClient mailClient)
      Creates a new MailMessage instance using the provided MailClient.

      This is a factory method that delegates the creation of the MailMessage instance to the provided MailClient. The MailClient is expected to implement the logic for creating a new MailMessage.

      Parameters:
      mailClient - the MailClient that will create the MailMessage
      Returns:
      a new MailMessage instance
    • getFrom

      org.eclipse.collections.api.list.ImmutableList<String> getFrom()
      Returns the "From" attribute addresses. The "From" attribute contains the identity of the person(s) who wished this message to be sent.

      This method returns null if this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.

      Returns:
      immutable list of Strings containing the addresses of the sender
      Throws:
      MailException - if the sender address fails to be retrieved
    • setFrom

      void setFrom(String address)
      Set the "From" attribute address in this message.
      Parameters:
      address - the sender address
      Throws:
      MailException - if the sender address fails to be set
    • addFrom

      void addFrom(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Add these addresses to the existing "From" attribute.
      Parameters:
      addresses - the sender addresses
      Throws:
      MailException - if the sender addresses fail to be added
    • getTo

      org.eclipse.collections.api.list.ImmutableList<String> getTo()
      Returns the "To" attribute addresses. The "To" attribute contains the primary recipients of this message.

      This method returns null if this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.

      Returns:
      immutable list of Strings containing the addresses of the primary recipients
      Throws:
      MailException - if the primary recipient addresses fail to be retrieved
    • setTo

      void setTo(String address)
      Set the "To" attribute address in this message.
      Parameters:
      address - the primary recipient address
      Throws:
      MailException - if the primary recipient address fail to be set
    • setTo

      void setTo(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Set the "To" attribute addresses in this message.
      Parameters:
      addresses - the primary recipient addresses
      Throws:
      MailException - if the primary recipient addresses fail to be set
    • addTo

      void addTo(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Add these addresses to the existing "To" attribute.
      Parameters:
      addresses - the primary recipient addresses
      Throws:
      MailException - if the primary recipient addresses fail to be added
    • getCc

      org.eclipse.collections.api.list.ImmutableList<String> getCc()
      Return the "Cc" attribute addresses. The "Cc" attribute contains secondary recipients of this message.

      This method returns null if this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.

      Returns:
      immutable list of Strings containing the addresses of the secondary recipients
      Throws:
      MailException - if the secondary recipient addresses fail to be retrieved
    • setCc

      void setCc(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Set the "Cc" attribute addresses in this message.
      Parameters:
      addresses - the secondary recipient addresses
      Throws:
      MailException - if the secondary recipient addresses fail to be set
    • addCc

      void addCc(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Add these addresses to the existing "Cc" attribute.
      Parameters:
      addresses - the secondary recipient addresses
      Throws:
      MailException - if the secondary recipient addresses fail to be added
    • getBcc

      org.eclipse.collections.api.list.ImmutableList<String> getBcc()
      Return the "Bcc" attribute addresses. The "Bcc" attribute contains tertiary recipients of this message.

      This method returns null if this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.

      Returns:
      immutable list of Strings containing the addresses of the tertiary recipients
      Throws:
      MailException - if the tertiary recipient addresses fail to be retrieved
    • setBcc

      void setBcc(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Set the "Bcc" attribute addresses in this message.
      Parameters:
      addresses - the tertiary recipient addresses
      Throws:
      MailException - if the tertiary recipient addresses fail to be set
    • addBcc

      void addBcc(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Add these addresses to the existing "Bcc" attribute.
      Parameters:
      addresses - the tertiary recipient addresses
      Throws:
      MailException - if the tertiary recipient addresses fail to be added
    • getAllRecipients

      org.eclipse.collections.api.list.ImmutableList<String> getAllRecipients()
      Get all the recipients of this message. This method returns null if the corresponding header is not present. Returns an empty array if the header is present, but contains no addresses.
      Returns:
      all the recipients of this message
      Throws:
      MailException - if the recipients fail to be retrieved
    • getReplyTo

      org.eclipse.collections.api.list.ImmutableList<String> getReplyTo()
      Get the addresses to which replies should be directed. This will usually be the sender of the message, but some messages may direct replies to a different address.

      The default implementation simply calls the getFrom method.

      This method returns null if the corresponding header is not present. Returns an empty array if the header is present, but contains no addresses.

      Returns:
      addresses to which replies should be directed
      Throws:
      MailException - if the reply-to addresses fail to be retrieved
      See Also:
    • setReplyTo

      void setReplyTo(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Set the addresses to which replies should be directed. (Normally only a single address will be specified.) Not all message types allow this to be specified separately from the sender of the message.

      The default implementation provided here just throws the MethodNotSupportedException.

      Parameters:
      addresses - addresses to which replies should be directed
      Throws:
      MailException - if the reply-to addresses fail to be set
    • getSubject

      String getSubject()
      Get the subject of this message.
      Returns:
      the subject string
      Throws:
      MailException - if the subject fails to be retrieved
    • setSubject

      void setSubject(String subject)
      Set the subject of this message.
      Parameters:
      subject - the subject string
      Throws:
      MailException - if the subject fails to be set
    • setText

      void setText(String text)
      A convenience method that sets the given String as this part's content with a MIME type of "text/plain".
      Parameters:
      text - the text that is the message's content
      Throws:
      MailException - if the text fails to be set
    • setHtml

      void setHtml(String htmlText)
      A convenience method that sets the given String as this part's content with a MIME type of "text/html".
      Parameters:
      htmlText - the html content that is the message's content
      Throws:
      MailException - if the html content fails to be set
    • addAttachment

      void addAttachment(File file)
      Adds a File as an attachment to this message.
      Parameters:
      file - the file to attach
      Throws:
      MailException - if an error occurs while attaching the file
    • addAttachment

      void addAttachment(File file, String cid)
      Adds a File as an attachment to this message with the given content ID.
      Parameters:
      file - the file to attach
      cid - the "Content-ID" of the attachment
      Throws:
      MailException - if an error occurs while attaching the file
    • addAttachment

      void addAttachment(File file, String contentType, String encoding)
      Adds a File as an attachment to this message with the given content type and encoding.
      Parameters:
      file - the file to attach
      contentType - the content type of the file
      encoding - the encoding of the file
      Throws:
      MailException - if an error occurs while attaching the file
    • getSentDate

      Instant getSentDate()
      Get the date this message was sent.
      Returns:
      the instant this message was sent
      Throws:
      MailException - if the sent date fails to be retrieved
    • setSentDate

      void setSentDate(Instant instant)
      Set the sent date of this message.
      Parameters:
      instant - the instant this message was sent
      Throws:
      MailException - if the sent date fails to be set
    • getReceivedDate

      Instant getReceivedDate()
      Get the date this message was received.
      Returns:
      the instant this message was received
      Throws:
      MailException - if the received date fails to be retrieved
    • saveChanges

      CompletableFuture<Void> saveChanges()
      Save any changes made to this message into the message-store when the containing folder is closed, if the message is contained in a folder. Update any header fields to be consistent with the changed message contents. If any part of a message's headers or contents are changed, this method must be called to ensure that those changes are permanent. If this method is not called, any such modifications may or may not be saved, depending on the message store and folder implementation.

      Messages obtained from folders opened READ_ONLY should not be modified and saveChanges should not be called on such messages.

      Returns:
      a CompletableFuture that completes when the changes are saved
      Throws:
      MailException - if the changes fail to be saved
    • send

      Send a message. The message will be sent to all recipient addresses specified in the message (as returned from the method getAllRecipients()), using message transports appropriate to each address. The send method calls the saveChanges method on the message before sending it.

      In typical usage, a MailException reflects an error detected by the server. The details of the MailException will usually contain the error message from the server (such as an SMTP error message). An address may be detected as invalid for a variety of reasons - the address may not exist, the address may have invalid syntax, the address may have exceeded its quota, etc.

      Returns:
      a CompletableFuture that completes when the message is sent
      Throws:
      MailException - if the message fails to be sent
      See Also:
    • send

      CompletableFuture<Void> send(org.eclipse.collections.api.list.ImmutableList<String> addresses)
      Send the message to the specified addresses, ignoring any recipients specified in the message itself. The send method calls the saveChanges method on the message before sending it.
      Parameters:
      addresses - the addresses to which to send the message
      Returns:
      a CompletableFuture that completes when the message is sent
      Throws:
      MailException - if the message fails to be sent
      See Also: