Guest User

Untitled

a guest
Jan 23rd, 2018
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. DEBUG: getProvider() returning
  2.  
  3. javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
  4. DEBUG SMTP: useEhlo true, useAuth true
  5. DEBUG SMTP: useEhlo true, useAuth true
  6. DEBUG SMTP: trying to connect to host "smtp.yandex.ru", port 995, isSSL false
  7.  
  8. Properties props = new Properties();
  9. props.put("mail.smtp.starttls.enable", "true");//Enable tls session
  10. props.put("mail.smtp.auth", "true");//Enable authentication
  11. props.put("mail.smtp.host", "smtp.yandex.ru");//Server's host
  12. props.put("mail.smtp.port", "995");//Server's port
  13.  
  14. Session session = Session.getInstance(props,
  15. new javax.mail.Authenticator() {
  16. protected PasswordAuthentication getPasswordAuthentication() {
  17. return new PasswordAuthentication("name@domain.ru", "password102030");
  18. }
  19. });
  20. session.setDebug(true);
  21.  
  22.  
  23. try {
  24.  
  25. Scanner to = new Scanner(toWho);
  26. while (to.hasNextLine())
  27. {
  28. String touser = to.nextLine();
  29.  
  30. try {
  31. if (howMany <= batch)
  32. {
  33. howMany++;
  34. System.out.println("Задержка "+delayevery/1000+" секунд");
  35. Thread.sleep(delayevery);
  36. }
  37. else
  38. {
  39. howMany = 0;
  40. System.out.println("Задержка "+delaybatch/1000+" секунд");
  41. Thread.sleep(delaybatch);
  42. }
  43. Message message = new MimeMessage(session);
  44. message.setFrom(new InternetAddress(username,alias));
  45.  
  46. message.setRecipients(Message.RecipientType.TO,
  47. InternetAddress.parse(touser));
  48. message.setSubject(subject);
  49.  
  50.  
  51. // Create the message part
  52. BodyPart messageBodyPart = new MimeBodyPart();
  53. BodyPart imagePart = new MimeBodyPart();
  54.  
  55. if (image != "")
  56. imagePart.setContent("<img src=""+image+"">","text/html");
  57. // Now set the actual message
  58. messageBodyPart.setText(MailSender.message);
  59.  
  60. // Create a multipar message
  61. Multipart multipart = new MimeMultipart();
  62. //Set image message part
  63. multipart.addBodyPart(imagePart);
  64. // Set text message part
  65. multipart.addBodyPart(messageBodyPart);
  66.  
  67. // Part two is attachment
  68. messageBodyPart = new MimeBodyPart();
  69.  
  70. if (attaching != "")
  71. {
  72. DataSource source = new FileDataSource(attaching);
  73. messageBodyPart.setDataHandler(new DataHandler(source));
  74.  
  75. messageBodyPart.setFileName(javax.mail.internet.MimeUtility.encodeWord(source.getName(),
  76. "UTF-8", null));
  77. multipart.addBodyPart(messageBodyPart);
  78. }
  79. // Send the complete message parts
  80. message.setContent(multipart);
  81.  
  82.  
  83. Transport.send(message);
  84.  
  85. System.out.println("Done "+(++counter));
  86.  
  87. } catch (MessagingException e) {
  88. throw new RuntimeException(e);
  89. } catch (UnsupportedEncodingException ex) {
  90. Logger.getLogger(MailSender.class.getName()).log(Level.SEVERE, null, ex);
  91. }
  92.  
  93. }
  94.  
  95. } catch (FileNotFoundException ex) {
  96. System.out.print("База была не найдена.");
  97. } catch (InterruptedException ex) {
  98. System.out.print("Что-то неверно.");
  99. }
  100.  
  101. props.put("mail.smtp.ssl.enable", "true");
Add Comment
Please, Sign In to add comment