Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package mail;
  7. import java.util.Properties;
  8.  
  9. import javax.mail.Message;
  10. import javax.mail.MessagingException;
  11. import javax.mail.PasswordAuthentication;
  12. import javax.mail.Session;
  13. import javax.mail.Transport;
  14. import javax.mail.internet.InternetAddress;
  15. import javax.mail.internet.MimeMessage;
  16.  
  17. public class Mail {
  18.  
  19. public static void main(String[] args) {
  20.  
  21. String to = "stezenkok@gmail.com";
  22. final String username = "stezenkok6@gmail.com";
  23. final String password = "ASDQWE";
  24. String host = "smtp.gmail.com";
  25.  
  26. Properties props = new Properties();
  27. props.put("mail.smtp.auth", "true");
  28. props.put("mail.smtp.starttls.enable", "true");
  29. props.put("mail.smtp.host", host);
  30. props.put("mail.smtp.port", "587");
  31.  
  32. Session session = Session.getInstance(props,
  33. new javax.mail.Authenticator() {
  34. protected PasswordAuthentication getPasswordAuthentication() {
  35. return new PasswordAuthentication(username, password);
  36. }
  37. });
  38.  
  39. try {
  40. Message message = new MimeMessage(session);
  41.  
  42. message.setRecipients(Message.RecipientType.TO,
  43. InternetAddress.parse(to));
  44.  
  45. message.setSubject("Testing15444");
  46.  
  47. message.setText("hello "
  48. + "kak dela? ");
  49.  
  50. Transport.send(message);
  51.  
  52. System.out.println("Sent message successfully....");
  53.  
  54. } catch (MessagingException e) {
  55. throw new RuntimeException(e);
  56. }
  57.  
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement