Advertisement
Guest User

Untitled

a guest
Dec 4th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1.  
  2. import javax.mail.Message;
  3. import javax.mail.MessagingException;
  4. import javax.mail.PasswordAuthentication;
  5. import javax.mail.internet.*;
  6. import javax.mail.*;
  7. import java.util.Properties;
  8.  
  9. public class Mail {
  10.  
  11. public static void main(String[] args) throws MessagingException {
  12. Properties p = new Properties();
  13. p.put("mail.smtp.host", "smtp.yandex.ru");
  14. p.put("mail.smtp.socketFactory.port", 465);
  15. p.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
  16. p.put("mail.smtp.auth", "true");
  17. p.put("mail.smtp.port", 465);
  18.  
  19. Session session = Session.getDefaultInstance(p,
  20. new javax.mail.Authenticator(){
  21. protected PasswordAuthentication getPasswordAuthentication(){
  22. return new PasswordAuthentication("notification.netcracker@yandex.ru", "netcrackerproject");
  23. }
  24. });
  25. try{
  26. MimeMessage mess = new MimeMessage(session);
  27. mess.setFrom(new InternetAddress("notification.netcracker@yandex.ru"));
  28. mess.setRecipients(Message.RecipientType.TO, InternetAddress.parse("calomonbkm@gmail.com"));
  29. mess.setSubject("Test");
  30. mess.setText("TEST");
  31. Transport.send(mess);
  32. System.out.println("Готово!");
  33. }catch (Exception ex){
  34. ex.printStackTrace();
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement