Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.42 KB | None | 0 0
  1. package stormnet;
  2.  
  3. import java.util.Properties;
  4.  
  5. import javax.mail.Message;
  6. import javax.mail.MessagingException;
  7. import javax.mail.PasswordAuthentication;
  8. import javax.mail.Session;
  9. import javax.mail.Transport;
  10. import javax.mail.internet.AddressException;
  11. import javax.mail.internet.InternetAddress;
  12. import javax.mail.internet.MimeMessage;
  13.  
  14. public class MailSender {
  15.  
  16. /**
  17. * @param args
  18. */
  19. public static void main(String[] args) {
  20. // TODO Auto-generated method stub
  21. final String userName = "javamailer12@gmail.com";
  22. final String password = "artificialintelligence";
  23.  
  24. Properties props = new Properties();
  25. props.put("mail.smtp.auth", "true");
  26. props.put("mail.smtp.starttls.enable", "true");
  27. props.put("mail.smtp.host", "smtp.gmail.com");
  28. props.put("mail.smtp.port", "587");
  29.  
  30. Session session = Session.getInstance(props, new javax.mail.Authenticator(){
  31. protected javax.mail.PasswordAuthentication getPasswordAuthentication(){
  32. return new PasswordAuthentication(userName, password);
  33. }
  34. });
  35.  
  36. try{
  37. Message message = new MimeMessage(session);
  38. message.setFrom(new InternetAddress("javamailer12@gmail.com"));
  39. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("mishazxc@mail.ru"));
  40. message.setSubject("tEST subject");
  41. message.setText("Hi! Dat testing java mail");
  42.  
  43. Transport.send(message);
  44. System.out.println("Done!");
  45. }
  46. catch(AddressException ex){
  47.  
  48. }
  49. catch(MessagingException ex){
  50.  
  51. }
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement