Advertisement
Guest User

Untitled

a guest
May 31st, 2017
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import java.util.Properties;
  2. import javax.mail.Message;
  3. import javax.mail.MessagingException;
  4. import javax.mail.PasswordAuthentication;
  5. import javax.mail.Session;
  6. import javax.mail.Transport;
  7. import javax.mail.internet.InternetAddress;
  8. import javax.mail.internet.MimeMessage;
  9.  
  10. public class Test {
  11. public static void main(String[] args) {
  12. Properties props = new Properties();
  13. props.put("mail.smtp.host", "smtp.gmail.com");
  14. props.put("mail.smtp.socketFactory.port", "465");
  15. props.put("mail.smtp.socketFactory.class",
  16. "javax.net.ssl.SSLSocketFactory");
  17. props.put("mail.smtp.auth", "true");
  18. props.put("mail.smtp.port", "465");
  19.  
  20. Session session = Session.getDefaultInstance(props,
  21. new javax.mail.Authenticator() {
  22. protected PasswordAuthentication getPasswordAuthentication() {
  23. return new PasswordAuthentication("storemanagering@gmail.com","sen ozunkun yaz");
  24. }
  25. });
  26.  
  27. try {
  28.  
  29. Message message = new MimeMessage(session);
  30. message.setFrom(new InternetAddress("storemanagering@gmail.com"));
  31. message.setRecipients(Message.RecipientType.TO,
  32. InternetAddress.parse("nurlanagayev307@gmail.com"));
  33. message.setSubject("Testing Subject");
  34. message.setText("Dear Mail Crawler," +
  35. "\n\n No spam to my email, please!");
  36.  
  37. Transport.send(message);
  38.  
  39. System.out.println("Done");
  40.  
  41. } catch (MessagingException e) {
  42. throw new RuntimeException(e);
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement