Class MailTools

java.lang.Object
cn.starrys.tool.mail.MailTools

public class MailTools extends Object
邮件工具。

creationTime: 2023/1/12 13:31 .

Author:
XingKong
  • Constructor Details

    • MailTools

      public MailTools(@NotNull @NotNull String host, @NotNull @NotNull Integer port, @NotNull @NotNull String from, @NotNull @NotNull String password)
      最简构造。
      Parameters:
      host - 主机。
      port - 主机端口。
      from - 发件邮箱。
      password - 发件邮箱授权码。
    • MailTools

      public MailTools(@NotNull @NotNull String host, @NotNull @NotNull Integer port, @NotNull @NotNull String from, @NotNull @NotNull String password, String nickname)
      重载构造。
      Parameters:
      host - 主机。
      port - 主机端口。
      from - 发件邮箱。
      password - 发件邮箱授权码。
      nickname - 昵称。
    • MailTools

      public MailTools(@NotNull @NotNull String host, @NotNull @NotNull Integer port, @NotNull @NotNull String from, @NotNull @NotNull String password, String nickname, boolean ssl)
      重载构造。
      Parameters:
      host - 主机。
      port - 主机端口。
      from - 发件邮箱。
      password - 发件邮箱授权码。
      nickname - 昵称。
      ssl - 启用 ssl。
    • MailTools

      public MailTools(@NotNull @NotNull String host, @NotNull @NotNull Integer port, @NotNull @NotNull String from, @NotNull @NotNull String password, String nickname, boolean ssl, boolean debug)
      重载构造。
      Parameters:
      host - 主机。
      port - 主机端口。
      from - 发件邮箱。
      password - 发件邮箱授权码。
      nickname - 昵称。
      ssl - 启用 ssl。
      debug - 开启debug模式。
    • MailTools

      public MailTools(@NotNull @NotNull MailProps mailProps)
      最终构造方法
      Parameters:
      mailProps - MailProps 邮件配置。
  • Method Details

    • getSession

      public jakarta.mail.Session getSession(@NotNull MailProps.Protocols protocol)
      获取 Session 对象.
      Parameters:
      protocol - 指定协议
      Returns:
      Session 对象
    • createMimeMessage

      public jakarta.mail.internet.MimeMessage createMimeMessage(jakarta.mail.Session session, @NotNull @NotNull Mail mail)
      创建邮件。
      Parameters:
      session - Session对象。
      mail - Mail 邮件内容。
      Returns:
      一封邮件。
    • send

      public boolean send(String addressee, String subject, String body)
      发送邮件。
      Parameters:
      addressee - 收件人。
      subject - 邮件主题(标题)。
      body - 邮件内容(主体)。
      Returns:
      发送结果。
    • send

      public boolean send(String addressee, String nickname, String subject, String body)
      发送邮件。
      Parameters:
      addressee - 收件人。
      nickname - 收件者昵称。
      subject - 邮件主题(标题)。
      body - 邮件内容(主体)。
      Returns:
      发送结果。
    • send

      public boolean send(String addressee, String nickname, String subject, String body, List<File> attachments)
      发送邮件。
      Parameters:
      addressee - 收件人。
      nickname - 收件者昵称。
      subject - 邮件主题(标题)。
      body - 邮件内容(主体)。
      attachments - 附件。
      Returns:
      发送结果。
    • send

      public boolean send(List<MailAddressee> to, String subject, String body, List<File> attachments)
      发送邮件。
      Parameters:
      to - 收件人(主要收件人)。
      subject - 邮件主题(标题)。
      body - 邮件内容(主体)。
      attachments - 附件。
      Returns:
      发送结果。
    • send

      public boolean send(Mail mail)
      发送邮件。
      Parameters:
      mail - Mail 邮件内容。
      Returns:
      发送结果。
    • send

      public boolean send(jakarta.mail.internet.MimeMessage msg)
      最终执行发送方法。
      Parameters:
      msg - 一封邮件。
      Returns:
      发送结果。