Interface MailSender


public interface MailSender
Builds a multi-part mail message and sends it to one or more recipients.
  • Method Details

    • clear

      void clear()
      Clears the state of this mail sender and releases internal resources.
    • addRecipients

      MailSender addRecipients(String... recipients) throws Exception
      Adds a list of recipient mail addresses to this mail sender. Each element in this list may contain one single mail address, or a comma separated list of mail addresses.
      Parameters:
      recipients - list of recipient mail addresses to add.
      Returns:
      this updated mail sender for method chaining.
      Throws:
      IllegalArgumentException - if a mail address is invalid.
      Exception - if an unexpected error occurs.
    • setSubject

      MailSender setSubject(String subject) throws Exception
      Sets the message subject of this mail sender.
      Parameters:
      subject - the message subject of this mail sender.
      Returns:
      this updated mail sender for method chaining.
      Throws:
      NullPointerException - if subject is null.
      IllegalArgumentException - if subject is invalid.
      Exception - if an unexpected error occurs.
    • setMessage

      MailSender setMessage(String message) throws Exception
      Sets the message body of this mail sender.
      Parameters:
      message - the message body of this mail sender.
      Returns:
      this updated mail sender for method chaining.
      Throws:
      NullPointerException - if message is null.
      IllegalArgumentException - if message is invalid.
      Exception - if an unexpected error occurs.
    • addPart

      MailSender addPart(File file) throws Exception
      Adds a file part to this mail sender.
      Parameters:
      file - the file part to add to this mail sender.
      Returns:
      this updated mail sender for method chaining.
      Throws:
      NullPointerException - if file is null.
      IllegalArgumentException - if file is invalid.
      Exception - if an unexpected error occurs.
    • addPart

      MailSender addPart(File file, String type) throws Exception
      Adds a file part with type to this mail sender.
      Parameters:
      file - the file part to add to this mail sender.
      type - the content type of the supplied file.
      Returns:
      this updated mail sender for method chaining.
      Throws:
      NullPointerException - if an argument is null.
      IllegalArgumentException - if an argument is invalid.
      Exception - if an unexpected error occurs.
    • addPart

      MailSender addPart(byte[] bytes) throws Exception
      Adds a bytes part to the this mail sender.
      Parameters:
      bytes - the bytes part to add to this mail sender.
      Returns:
      this updated mail sender for method chaining.
      Throws:
      NullPointerException - if bytes is null.
      IllegalArgumentException - if bytes is invalid.
      Exception - if an unexpected error occurs.
    • addPart

      MailSender addPart(byte[] bytes, String type) throws Exception
      Adds a bytes part with type to this mail sender.
      Parameters:
      bytes - the bytes part to add to this mail sender.
      type - the content type of the supplied bytes.
      Returns:
      this updated mail sender for method chaining.
      Throws:
      NullPointerException - if an argument is null.
      IllegalArgumentException - if an argument is invalid.
      Exception - if an unexpected error occurs.
    • addPart

      MailSender addPart(byte[] bytes, String type, String name) throws Exception
      Adds a bytes part with type and name to this mail sender.
      Parameters:
      bytes - the bytes part to add to this mail sender.
      type - the content type of the supplied bytes.
      name - the optional name of the supplied bytes.
      Returns:
      this updated mail sender for method chaining.
      Throws:
      NullPointerException - if an argument is null.
      IllegalArgumentException - if an argument is invalid.
      Exception - if an unexpected error occurs.
    • send

      void send() throws Exception
      Builds the mail message and sends it to the specified recipients.
      Throws:
      Exception - if an unexpected error occurs.