Class Mail

java.lang.Object
io.mangoo.email.Mail

public class Mail extends Object
Author:
svenkubiak
  • Constructor Details

    • Mail

      public Mail()
  • Method Details

    • newMail

      public static Mail newMail()
      Creates a new mail instance
      Returns:
      A mail object instance
    • to

      public Mail to(String... tos)
      Sets one or more TO address
      Parameters:
      tos - Address may be specified with personal name like this: Jenny Doe <email@foo.com>.
      Returns:
      A mail object instance
    • cc

      public Mail cc(String... ccs)
      Sets one or more CC address
      Parameters:
      ccs - array of Strings to set.
      Returns:
      A mail object instance
    • bcc

      public Mail bcc(String... bccs)
      Sets one or more BCC address
      Parameters:
      bccs - array of Strings to set.
      Returns:
      A mail object instance
    • subject

      public Mail subject(String subject)
      Sets message subject with specified encoding to override default platform encoding. The application must ensure that the subject does not contain any line breaks.
      Parameters:
      subject - The message subject
      Returns:
      A mail object instance
    • from

      public Mail from(String fromName, String fromAddress)
      Sets the FROM address and name
      Parameters:
      fromName - The name of the sender e.g. Peter Parker
      fromAddress - Address may be specified with personal name like this: email@foo.com
      Returns:
      A mail object instance
    • from

      public Mail from(String fromAddress)
      Sets the FROM address
      Parameters:
      fromAddress - Address may be specified with personal name like this: email@foo.com
      Returns:
      A mail object instance
    • header

      public Mail header(String name, String value)
      Adds a header value
      Parameters:
      name - The name of the header
      value - The value of the header
      Returns:
      A mail object instance
    • replyTo

      public Mail replyTo(String replyTo)
      Sets REPLY-TO address
      Parameters:
      replyTo - Address may be specified with personal name like this: Jenny Doe <email@foo.com>
      Returns:
      A mail object instance
    • priority

      public Mail priority(int priority)
      Sets the email priority
      Parameters:
      priority - - 1 being the highest priority, 3 = normal priority and 5 = lowest priority
      Returns:
      A mail object instance
    • attachment

      public Mail attachment(Path path)
      Adds a file as attachment to the mail
      Parameters:
      path - The Path to attach
      Returns:
      A mail object instance
    • attachments

      public Mail attachments(List<Path> paths)
      Adds a list of files as attachment to the mail
      Parameters:
      paths - The Path files to attach
      Returns:
      A mail object instance
    • textMessage

      public Mail textMessage(String message)
      Adds plain message text
      Parameters:
      message - The text to add as a String.
      Returns:
      A mail object instance
    • htmlMessage

      public Mail htmlMessage(String message)
      Adds html message text.
      Parameters:
      message - The text to add as a String.
      Returns:
      A mail object instance
    • textMessage

      public Mail textMessage(String template, Map<String,Object> content) throws MangooTemplateEngineException
      Adds plain message text which uses a given template and content to render
      Parameters:
      template - The template to render
      content - The content to pass to the template
      Returns:
      A mail object instance
      Throws:
      MangooTemplateEngineException - when rendering the template failed
    • htmlMessage

      public Mail htmlMessage(String template, Map<String,Object> content) throws MangooTemplateEngineException
      Adds html message text which uses a given template and content to render
      Parameters:
      template - The template to render
      content - The content to pass to the template
      Returns:
      A mail object instance
      Throws:
      MangooTemplateEngineException - when rendering the template failed
    • send

      public void send()
      Sends the mail
    • getMessageHeaders

      public Map<String,String> getMessageHeaders()
    • getMessageTos

      public List<String> getMessageTos()
    • getMessageCcs

      public List<String> getMessageCcs()
    • getMessageBccs

      public List<String> getMessageBccs()
    • getMessageAttachments

      public List<Path> getMessageAttachments()
    • getMessageSubject

      public String getMessageSubject()
    • getMessageReplyTo

      public String getMessageReplyTo()
    • getMessageText

      public String getMessageText()
    • getMessageFromName

      public String getMessageFromName()
    • getMessageFromAddress

      public String getMessageFromAddress()
    • isMessageHtml

      public boolean isMessageHtml()
    • hasAttachments

      public boolean hasAttachments()