Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.commons.mail.DefaultAuthenticator;
- import org.apache.commons.mail.Email;
- import org.apache.commons.mail.SimpleEmail;
- /**
- * Created by - on 09/05/2017.
- */
- public class SimpleEmailSender
- {
- private static final String HOST = "smtp.gmail.com";
- private static final int PORT = 465;
- private static final boolean SSL_FLAG = true;
- public static void main(String[] args) throws InterruptedException
- {
- SimpleEmailSender sender = new SimpleEmailSender();
- sender.sendSimpleEmail();
- }
- private void sendSimpleEmail()
- {
- String userName = "login@gmail.com";
- String password = "password";
- String fromAddress="username@gmail.com";
- String toAddress = "example@gmail.com";
- String subject = "Хэллоу";
- String message = "Добрый день! Этот чертов гугл уже заколебал своими настройками";
- try
- {
- Email email = new SimpleEmail();
- email.setHostName(HOST);
- email.setSmtpPort(PORT);
- email.setAuthenticator(new DefaultAuthenticator(userName, password));
- email.setSSLOnConnect(SSL_FLAG);
- email.setFrom(fromAddress);
- email.setSubject(subject);
- email.setMsg(message);
- email.addTo(toAddress);
- email.send();
- }
- catch(Exception ex)
- {
- System.out.println("Unable to send email");
- System.out.println(ex);
- }
- }
- }
Add Comment
Please, Sign In to add comment