java.lang.Object
org.miaixz.bus.extra.mail.MailKit
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic jakarta.mail.SessiongetSession(MailAccount mailAccount, boolean isSingleton) Retrieves a mailSessionbased on the provided mail account configuration.static StringSends an email to one or more recipients using the default account from the configuration.static Stringsend(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.static Stringsend(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.static Stringsend(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.static StringSends an email to a collection of recipients using the default account from the configuration.static Stringsend(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.static Stringsend(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.static Stringsend(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.static Stringsend(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.static Stringsend(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.static Stringsend(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.static Stringsend(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.static Stringsend(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.static Stringsend(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.static StringSends an HTML email to one or more recipients using the default account from the configuration.static StringsendHtml(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.static StringSends an HTML email to a collection of recipients using the default account from the configuration.static StringsendHtml(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.static StringSends a plain text email to one or more recipients using the default account from the configuration.static StringSends a plain text email to a collection of recipients using the default account from the configuration.
-
Constructor Details
-
MailKit
public MailKit()
-
-
Method Details
-
sendText
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
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
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-trueif the content is HTML,falsefor 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-trueif the content is HTML,falsefor 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-trueif the content is HTML,falsefor 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-trueif the content is HTML,falsefor 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-trueif the content is HTML,falsefor 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-trueif the content is HTML,falsefor 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-trueif the content is HTML,falsefor 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 toInputStreams 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 toInputStreams for embedded images.isHtml-trueif the content is HTML,falsefor 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 toInputStreams for embedded images.isHtml-trueif the content is HTML,falsefor 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 toInputStreams 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 toInputStreams for embedded images.isHtml-trueif the content is HTML,falsefor 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 toInputStreams for embedded images.isHtml-trueif the content is HTML,falsefor 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 toInputStreams for embedded images.isHtml-trueif the content is HTML,falsefor 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 toInputStreams for embedded images.isHtml-trueif the content is HTML,falsefor 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 toInputStreams for embedded images.isHtml-trueif the content is HTML,falsefor plain text.files- An array of files to be attached.- Returns:
- The message-id of the sent email.
-
getSession
Retrieves a mailSessionbased on the provided mail account configuration.- Parameters:
mailAccount- The mail account configuration.isSingleton- Iftrue, returns a globally shared session; otherwise, creates a new session.- Returns:
- A
Sessioninstance.
-