Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
41,965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. ```java
  2.  
  3. try {
  4. String to="go372900589@yeah.net";
  5. String from="wzhonggo@outlook.com";
  6.  
  7. Properties props = new Properties();
  8. // props.put("mail.smtp.socketFactory.port", "587");
  9. // props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  10. // props.put("mail.smtp.socketFactory.fallback", "true");
  11. props.put("mail.smtp.host", "smtp-mail.outlook.com");
  12. props.put("mail.smtp.port", "587");
  13. props.put("mail.smtp.starttls.enable","true");
  14. props.put("mail.smtp.auth", "true");
  15.  
  16. Session session = Session.getDefaultInstance(props,
  17. new javax.mail.Authenticator() {
  18. protected PasswordAuthentication getPasswordAuthentication() {
  19. return new PasswordAuthentication("wzhonggo@outlook.com","xxxxxxxx");
  20. }
  21. });
  22.  
  23. // Session emailSession = Session.getDefaultInstance(props, null);
  24.  
  25. String msgBody = "Sending email using JavaMail API...";
  26.  
  27. Message msg = new MimeMessage(session);
  28. msg.setFrom(new InternetAddress(from, "NoReply"));
  29. msg.addRecipient(Message.RecipientType.TO,
  30. new InternetAddress(to, "Mr. Recipient"));
  31. msg.setSubject("Welcome To Java Mail API");
  32. msg.setText(msgBody);
  33. Transport.send(msg);
  34. System.out.println("Email sent successfully...");
  35. logger.error("Email sent successfully...");
  36. } catch (AddressException e) {
  37. logger.error(e.getMessage());
  38. } catch (MessagingException e) {
  39. logger.error(e.getMessage());
  40. } catch (UnsupportedEncodingException e) {
  41. logger.error(e.getMessage());
  42. }
  43. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement