Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import java.io.PrintStream;
  2. import java.util.Properties;
  3. import javax.mail.Authenticator;
  4. import javax.mail.Message;
  5. import javax.mail.Message.RecipientType;
  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.InternetAddress;
  11. import javax.mail.internet.MimeMessage;
  12.  
  13. public class GoogleMail
  14. {
  15. public static void sendEmail(String text, String subject, String recipient)
  16. {
  17. String username = "myemail@gmail.com";
  18. final String password = "gmailpassword";
  19.  
  20. Properties props = System.getProperties();
  21.  
  22. props.put("mail.smtp.starttls.enable", "true");
  23. props.put("mail.smtp.host", "smtp.gmail.com");
  24. props.put("mail.smtp.user", username);
  25. props.put("mail.smtp.password", password);
  26. props.put("mail.smtp.port", "587");
  27. props.put("mail.smtp.auth", "true");
  28.  
  29. Session session = Session.getInstance(props, new Authenticator()
  30. {
  31. protected PasswordAuthentication getPasswordAuthentication()
  32. {
  33. return new PasswordAuthentication(this.val$username, password);
  34. }
  35. });
  36. try
  37. {
  38. Message message = new MimeMessage(session);
  39. message.setFrom(new InternetAddress("myemail@gmail.com"));
  40. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient@gmail.com"));
  41. message.setSubject("Confirmation");
  42. message.setText("Dear user,\n\nThank you for registering your account with our website. Your encrypted link will be shown below, make sure to click this to register your account, or hook your minecraft account with your website \n\n\nLink:");
  43.  
  44. Transport.send(message);
  45.  
  46. System.out.println("Done");
  47. }
  48. catch (MessagingException e)
  49. {
  50. e.printStackTrace();
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement