code: public static void sendEmail(Session session, Email email) throws Exception {
          if (StringUtils.isBlank(email.getFrom())) {
              throw new Exception("没有邮件发送者");
          }
  
          if (StringUtils.isBlank(email.getTo()) && StringUtils.isBlank(email.getBcc()) &&
                  StringUtils.isBlank(email.getCc())) {
              throw new Exception("没有邮件接收者");
          }
  
          // 获取发送邮件的信息类
          MimeMessage message = new MimeMessage(session);
  
          // 设置发送方邮件地址
          message.setFrom(new InternetAddress(email.getFrom()));
          // 设置发送类型和被发送方的邮件地址
          if (!email.getTo().isEmpty()) {
              message.setRecipients(RecipientType.TO, email.getTo());
          }
          if (!email.getCc().isEmpty()) {
              message.setRecipients(RecipientType.CC, email.getCc());
          }
          if (!email.getBcc().isEmpty()) {
              message.setRecipients(RecipientType.BCC, email.getBcc());
          }
          // 设置邮件主题
          message.setSubject(email.getSubject(), "utf-8");
          // 设置邮件内容
          MimeMultipart content = new MimeMultipart();
          // 邮件正文
          MimeBodyPart text = new MimeBodyPart();
          text.setContent(email.getContent(), email.getType());
          content.addBodyPart(text);
          // 设置附件
          if (email.getAttachments() != null) {
              for (AttachmentBean attachment : email.getAttachments()) {
                  MimeBodyPart part = new MimeBodyPart();
                  part.attachFile(attachment.getFile());
                  part.setFileName(MimeUtility.encodeText(attachment
                          .getFileName()));
                  if (attachment.getCid() != null) {
                      part.setContentID(attachment.getCid());
                  }
                  content.addBodyPart(part);
              }
          }
          // 将邮件内容添加到信息中
          message.setContent(content);
          // 发送邮件
          Transport.send(message);
      }
docs: 用来发送邮件
  
  @param session 与发送邮件的主机的连接(会话)
  @param email   写好的邮件
  @throws Exception 出现异常