Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import java.util.Properties;
  2.  
  3. import javax.mail.Message;
  4. import javax.mail.MessagingException;
  5. import javax.mail.PasswordAuthentication;
  6. import javax.mail.Session;
  7. import javax.mail.Transport;
  8. import javax.mail.internet.InternetAddress;
  9. import javax.mail.internet.MimeMessage;
  10.  
  11. public class SendMailTLS {
  12.  
  13. public static void main(String[] args) {
  14.  
  15. final String username = "kamilkompala@gmail.com";
  16. final String password = "haslo";
  17.  
  18. Properties props = new Properties();
  19. props.put("mail.smtp.auth", "true");
  20. props.put("mail.smtp.starttls.enable", "true");
  21. props.put("mail.smtp.host", "smtp.gmail.com");
  22. props.put("mail.smtp.port", "587");
  23.  
  24. Session session = Session.getInstance(props,
  25. new javax.mail.Authenticator() {
  26. protected PasswordAuthentication getPasswordAuthentication() {
  27. return new PasswordAuthentication(username, password);
  28. }
  29. });
  30.  
  31. try {
  32.  
  33. Message message = new MimeMessage(session);
  34. message.setFrom(new InternetAddress("kamilkompala@gmail.com"));
  35. message.setRecipients(Message.RecipientType.TO,
  36. InternetAddress.parse("shspamspam@onet.pl"));
  37. message.setSubject("Test");
  38. message.setText("Co tam u mamy ?");
  39.  
  40. Transport.send(message);
  41.  
  42. System.out.println("Done");
  43.  
  44. } catch (MessagingException e) {
  45. throw new RuntimeException(e);
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement