Module bus.extra

Class MailKit

java.lang.Object
org.miaixz.bus.extra.mail.MailKit

public class MailKit extends Object
A utility class for sending emails, built on top of the Jakarta Mail API. This class provides a set of static methods for conveniently sending plain text and HTML emails.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • MailKit

      public MailKit()
  • Method Details

    • sendText

      public static String sendText(String to, String subject, String content, File... files)
      Sends a plain text email to one or more recipients using the default account from the configuration. Multiple recipients can be separated by commas (,) or semicolons (;).
      Parameters:
      to - The recipient(s).
      subject - The email subject.
      content - The email body.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • sendHtml

      public static String sendHtml(String to, String subject, String content, File... files)
      Sends an HTML email to one or more recipients using the default account from the configuration. Multiple recipients can be separated by commas (,) or semicolons (;).
      Parameters:
      to - The recipient(s).
      subject - The email subject.
      content - The HTML email body.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(String to, String subject, String content, boolean isHtml, File... files)
      Sends an email to one or more recipients using the default account from the configuration. Multiple recipients can be separated by commas (,) or semicolons (;).
      Parameters:
      to - The recipient(s).
      subject - The email subject.
      content - The email body.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(String to, String cc, String bcc, String subject, String content, boolean isHtml, File... files)
      Sends an email to multiple recipients, including CC and BCC, using the default account from the configuration. Recipients, CCs, and BCCs can be separated by commas (,) or semicolons (;).
      Parameters:
      to - The recipient(s).
      cc - The CC recipient(s).
      bcc - The BCC recipient(s).
      subject - The email subject.
      content - The email body.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • sendText

      public static String sendText(Collection<String> tos, String subject, String content, File... files)
      Sends a plain text email to a collection of recipients using the default account from the configuration.
      Parameters:
      tos - A collection of recipient email addresses.
      subject - The email subject.
      content - The email body.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • sendHtml

      public static String sendHtml(Collection<String> tos, String subject, String content, File... files)
      Sends an HTML email to a collection of recipients using the default account from the configuration.
      Parameters:
      tos - A collection of recipient email addresses.
      subject - The email subject.
      content - The HTML email body.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(Collection<String> tos, String subject, String content, boolean isHtml, File... files)
      Sends an email to a collection of recipients using the default account from the configuration.
      Parameters:
      tos - A collection of recipient email addresses.
      subject - The email subject.
      content - The email body.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject, String content, boolean isHtml, File... files)
      Sends an email to multiple recipients, including CC and BCC, using the default account from the configuration.
      Parameters:
      tos - A collection of recipient email addresses.
      ccs - A collection of CC recipient email addresses (can be null or empty).
      bccs - A collection of BCC recipient email addresses (can be null or empty).
      subject - The email subject.
      content - The email body.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(MailAccount mailAccount, String to, String subject, String content, boolean isHtml, File... files)
      Sends an email to one or more recipients using a specified mail account.
      Parameters:
      mailAccount - The mail account configuration.
      to - The recipient(s), separated by commas or semicolons.
      subject - The email subject.
      content - The email body.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(MailAccount mailAccount, Collection<String> tos, String subject, String content, boolean isHtml, File... files)
      Sends an email to a collection of recipients using a specified mail account.
      Parameters:
      mailAccount - The mail account configuration.
      tos - A collection of recipient email addresses.
      subject - The email subject.
      content - The email body.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(MailAccount mailAccount, Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject, String content, boolean isHtml, File... files)
      Sends an email to multiple recipients, including CC and BCC, using a specified mail account.
      Parameters:
      mailAccount - The mail account configuration.
      tos - A collection of recipient email addresses.
      ccs - A collection of CC recipient email addresses (can be null or empty).
      bccs - A collection of BCC recipient email addresses (can be null or empty).
      subject - The email subject.
      content - The email body.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • sendHtml

      public static String sendHtml(String to, String subject, String content, Map<String,InputStream> imageMap, File... files)
      Sends an HTML email with embedded images to one or more recipients using the default account.
      Parameters:
      to - The recipient(s), separated by commas or semicolons.
      subject - The email subject.
      content - The HTML email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(String to, String subject, String content, Map<String,InputStream> imageMap, boolean isHtml, File... files)
      Sends an email with embedded images to one or more recipients using the default account.
      Parameters:
      to - The recipient(s), separated by commas or semicolons.
      subject - The email subject.
      content - The email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(String to, String cc, String bcc, String subject, String content, Map<String,InputStream> imageMap, boolean isHtml, File... files)
      Sends an email with embedded images to multiple recipients, including CC and BCC, using the default account.
      Parameters:
      to - The recipient(s), separated by commas or semicolons.
      cc - The CC recipient(s), separated by commas or semicolons.
      bcc - The BCC recipient(s), separated by commas or semicolons.
      subject - The email subject.
      content - The email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • sendHtml

      public static String sendHtml(Collection<String> tos, String subject, String content, Map<String,InputStream> imageMap, File... files)
      Sends an HTML email with embedded images to a collection of recipients using the default account.
      Parameters:
      tos - A collection of recipient email addresses.
      subject - The email subject.
      content - The HTML email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(Collection<String> tos, String subject, String content, Map<String,InputStream> imageMap, boolean isHtml, File... files)
      Sends an email with embedded images to a collection of recipients using the default account.
      Parameters:
      tos - A collection of recipient email addresses.
      subject - The email subject.
      content - The email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject, String content, Map<String,InputStream> imageMap, boolean isHtml, File... files)
      Sends an email with embedded images to multiple recipients, including CC and BCC, using the default account.
      Parameters:
      tos - A collection of recipient email addresses.
      ccs - A collection of CC recipient email addresses (can be null or empty).
      bccs - A collection of BCC recipient email addresses (can be null or empty).
      subject - The email subject.
      content - The email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(MailAccount mailAccount, String to, String subject, String content, Map<String,InputStream> imageMap, boolean isHtml, File... files)
      Sends an email with embedded images to one or more recipients using a specified mail account.
      Parameters:
      mailAccount - The mail account configuration.
      to - The recipient(s), separated by commas or semicolons.
      subject - The email subject.
      content - The email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(MailAccount mailAccount, Collection<String> tos, String subject, String content, Map<String,InputStream> imageMap, boolean isHtml, File... files)
      Sends an email with embedded images to a collection of recipients using a specified mail account.
      Parameters:
      mailAccount - The mail account configuration.
      tos - A collection of recipient email addresses.
      subject - The email subject.
      content - The email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • send

      public static String send(MailAccount mailAccount, Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject, String content, Map<String,InputStream> imageMap, boolean isHtml, File... files)
      Sends an email with embedded images to multiple recipients, including CC and BCC, using a specified mail account.
      Parameters:
      mailAccount - The mail account configuration.
      tos - A collection of recipient email addresses.
      ccs - A collection of CC recipient email addresses (can be null or empty).
      bccs - A collection of BCC recipient email addresses (can be null or empty).
      subject - The email subject.
      content - The email body.
      imageMap - A map of Content-IDs to InputStreams for embedded images.
      isHtml - true if the content is HTML, false for plain text.
      files - An array of files to be attached.
      Returns:
      The message-id of the sent email.
    • getSession

      public static jakarta.mail.Session getSession(MailAccount mailAccount, boolean isSingleton)
      Retrieves a mail Session based on the provided mail account configuration.
      Parameters:
      mailAccount - The mail account configuration.
      isSingleton - If true, returns a globally shared session; otherwise, creates a new session.
      Returns:
      A Session instance.