SHARE
TWEET

Untitled

a guest Dec 13th, 2016 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void sendMail(){
  2.         String userName = nickNameField.getText();
  3.         String password = passwordField.getText();
  4.  
  5.         Properties properties = new Properties();
  6.         properties.put("mail.smtp.auth", "true");
  7.         properties.put("mail.smtp.starttls.enable", "true");
  8.         properties.put("mail.smtp.host", "smtp.gmail.com");
  9.         properties.put("mail.smtp.port", "587");
  10.  
  11.         Session session = Session.getInstance(properties,
  12.                 new javax.mail.Authenticator() {
  13.                     protected PasswordAuthentication getPasswordAuthentication() {
  14.                         return new PasswordAuthentication(userName, password);
  15.                     }
  16.                 });
  17.         try {
  18.  
  19.             Message message = new MimeMessage(session);
  20.             try {
  21.                 message.setFrom(new InternetAddress(nickNameField.getText()));
  22.             } catch (MessagingException e) {
  23.                 e.printStackTrace();
  24.             }
  25.             message.setRecipients(Message.RecipientType.TO,
  26.                     InternetAddress.parse(whoIsYourDaddy.getText()));
  27.             message.setSubject(subject.getText());
  28.             message.setText(messageArea.getText());
  29.  
  30.             Transport.send(message);
  31.  
  32.             System.out.println("Done");
  33.  
  34.         } catch (MessagingException e) {
  35.             throw new RuntimeException(e);
  36.         }
  37.  
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top