Guest User

Untitled

a guest
Oct 7th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public void sendMail(/*String from,String to, String subject, String text*/) {
  2. String host = "smtp.naver.com";
  3. String user = "123123213@naver.com";
  4. String password = "123123123123";
  5.  
  6. Properties prop = new Properties();
  7. prop.put("mail.smtp.host", "smtp.naver.com");
  8. prop.put("mail.smtp.port", 587);
  9. prop.put("mail.smtp.auth", "true");
  10. prop.put("mail.smtp.ssl.enable", "true");
  11. prop.put("mail.smtp.ssl.trust", "smtp.naver.com");
  12.  
  13. Session session = Session.getDefaultInstance(prop, new javax.mail.Authenticator() {
  14. protected PasswordAuthentication getPasswordAuthentication() {
  15. return new PasswordAuthentication(user, password); }
  16. });
  17. try {
  18. MimeMessage message = new MimeMessage(session);
  19. message.setFrom(new InternetAddress(user));
  20. message.addRecipient(Message.RecipientType.TO, new InternetAddress("ktko@ktko.com"));
  21. // 메일 제목
  22. message.setSubject("KTKO SMTP TEST1111"); // 메일 내용
  23. message.setText("KTKO Success!!"); // send the message
  24. Transport.send(message);
  25. System.out.println("Success Message Send");
  26. }catch (MessagingException e) { e.printStackTrace(); System.out.println("에러"); }
  27.  
  28. }
Add Comment
Please, Sign In to add comment