Пример #1
0
 public static void main(String[] args) {
   Mail mail = new Mail();
   EmailBuilder emailBuilder =
       new EmailBuilder(EmailProvider.NetEase_163)
           .from(System.getenv("from"))
           .token(System.getenv("token"))
           .to(System.getenv("to"))
           .content("Say something")
           .title("Welcome Letter");
   mail.sendEmail(emailBuilder);
 }
Пример #2
0
  public synchronized void sendMail(Mail m) throws MessagingException {

    MimeMessage message = new MimeMessage(session);
    DataHandler handler =
        new DataHandler(new ByteArrayDataSource(m.getBody().getBytes(), "text/plain"));
    message.setSender(new InternetAddress(m.getSender()));
    message.setSubject(m.getSubject());
    message.setDataHandler(handler);
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(m.getRecipient()));
    Transport tr = session.getTransport("smtp");
    tr.connect(user, password);
    tr.send(message);
    tr.close();
  }