Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. package pl.codeme.hackathon.GrzmotoPtak;
  2.  
  3. import java.util.Properties;
  4. import java.util.Scanner;
  5.  
  6. import javax.mail.*;
  7. import javax.mail.internet.AddressException;
  8. import javax.mail.internet.InternetAddress;
  9. import javax.mail.internet.MimeMessage;
  10. import pl.codeme.hackathon.GrzmotoPtak.*;
  11.  
  12. public class App extends Config
  13. {
  14.  
  15. public static void main( String[] args )
  16. {
  17. final String username = "hackathon123456@gmail.com";
  18. final String password = "hack1234";
  19.  
  20. Session session = Session.getInstance(gmailProperties(),
  21. new javax.mail.Authenticator() {
  22. protected PasswordAuthentication getPasswordAuthentication() {
  23. return new PasswordAuthentication(username, password);
  24. }
  25. });
  26.  
  27. try {
  28. MimeMessage message = new MimeMessage(session);
  29. Address addressfrom = new InternetAddress("hackathon123456@gmail.com");
  30. Address addressto = new InternetAddress("adamkartanowicz@gmail.com");
  31. message.setFrom(addressfrom);
  32. message.setRecipient(Message.RecipientType.TO, addressto);
  33. message.setSubject("Test");
  34. message.setText("Testowa wiadomosc");
  35. Transport.send(message);
  36.  
  37. } catch (AddressException e) {} catch (MessagingException e) {}
  38.  
  39. System.out.println("Zrobione!");
  40.  
  41. }
  42.  
  43. public static Properties gmailProperties () {
  44. Properties props = new Properties();
  45. props.put("mail.smtp.auth", "true");
  46. props.put("mail.smtp.starttls.enable", "true");
  47. props.put("mail.smtp.host", "smtp.gmail.com");
  48. props.put("mail.smtp.port", "587");
  49. return props;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement