Guest User

Untitled

a guest
May 9th, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import org.apache.commons.mail.DefaultAuthenticator;
  2. import org.apache.commons.mail.Email;
  3. import org.apache.commons.mail.SimpleEmail;
  4.  
  5. /**
  6.  * Created by - on 09/05/2017.
  7.  */
  8. public class SimpleEmailSender
  9. {
  10.     private static final String HOST = "smtp.gmail.com";
  11.     private static final int PORT = 465;
  12.     private static final boolean SSL_FLAG = true;
  13.    
  14.     public static void main(String[] args) throws InterruptedException
  15.     {
  16.         SimpleEmailSender sender = new SimpleEmailSender();
  17.         sender.sendSimpleEmail();
  18.     }
  19.     private void sendSimpleEmail()
  20.     {
  21.         String userName = "login@gmail.com";
  22.         String password = "password";
  23.         String fromAddress="username@gmail.com";
  24.         String toAddress =  "example@gmail.com";
  25.         String subject = "Хэллоу";
  26.         String message = "Добрый день! Этот чертов гугл уже заколебал своими настройками";
  27.         try
  28.         {
  29.             Email email = new SimpleEmail();
  30.             email.setHostName(HOST);
  31.             email.setSmtpPort(PORT);
  32.             email.setAuthenticator(new DefaultAuthenticator(userName, password));
  33.             email.setSSLOnConnect(SSL_FLAG);
  34.             email.setFrom(fromAddress);
  35.             email.setSubject(subject);
  36.             email.setMsg(message);
  37.             email.addTo(toAddress);
  38.             email.send();
  39.         }
  40.         catch(Exception ex)
  41.         {
  42.             System.out.println("Unable to send email");
  43.             System.out.println(ex);
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment