Guest User

Untitled

a guest
Apr 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. public void sendMessage(String fromAddress, String toAddress, String emailSubject, String emailBody) throws AddressException,
  2. MessagingException {
  3. Properties props = System.getProperties();
  4. props.put("mail.smtp.host", "localhost");
  5. Session session = Session.getDefaultInstance(props, null);
  6. Message msg = new MimeMessage(session);
  7. msg.setFrom(new InternetAddress(fromAddress));
  8. msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(toAddress, false));
  9. msg.setSubject(emailSubject);
  10. msg.setText(emailBody);
  11. Transport.send(msg);
  12. }
Add Comment
Please, Sign In to add comment