Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import javax.mail.Session;
  2. import javax.mail.Transport;
  3. import javax.mail.internet.AddressException;
  4. import javax.mail.internet.InternetAddress;
  5. import javax.mail.internet.MimeMessage;
  6.  
  7.  
  8. public class EmailSendler {
  9.  
  10. public static void main(String[] args) {
  11.  
  12. final String username = "info@lincoln.moscow";
  13. final String password = "*********";
  14.  
  15. Properties props = new Properties();
  16. props.put("mail.smtp.starttls.enable", "true");
  17. props.put("mail.smtp.auth", "true");
  18. props.put("mail.smtp.host", "smtp.gmail.com");
  19. props.put("mail.smtp.port", "587");
  20.  
  21. Session session = Session.getInstance(props,
  22. new javax.mail.Authenticator() {
  23. protected PasswordAuthentication getPasswordAuthentication() {
  24. return new PasswordAuthentication(username, password);
  25. }
  26. });
  27.  
  28. try {
  29.  
  30. Message message = new MimeMessage(session);
  31. message.setFrom(new InternetAddress("info@lincoln.moscow"));
  32. message.setRecipients(Message.RecipientType.TO,
  33. InternetAddress.parse("i.mr.tuz@gmail.com"));
  34. message.setSubject("Тестовое сообщение");
  35. message.setText("Работай пожалуйста,"
  36. + "nn No spam to my email, please!");
  37.  
  38. Transport.send(message);
  39.  
  40. System.out.println("Done");
  41.  
  42. } catch (MessagingException e) {
  43. throw new RuntimeException(e);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement