Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DEBUG: getProvider() returning
- javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
- DEBUG SMTP: useEhlo true, useAuth true
- DEBUG SMTP: useEhlo true, useAuth true
- DEBUG SMTP: trying to connect to host "smtp.yandex.ru", port 995, isSSL false
- Properties props = new Properties();
- props.put("mail.smtp.starttls.enable", "true");//Enable tls session
- props.put("mail.smtp.auth", "true");//Enable authentication
- props.put("mail.smtp.host", "smtp.yandex.ru");//Server's host
- props.put("mail.smtp.port", "995");//Server's port
- Session session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("name@domain.ru", "password102030");
- }
- });
- session.setDebug(true);
- try {
- Scanner to = new Scanner(toWho);
- while (to.hasNextLine())
- {
- String touser = to.nextLine();
- try {
- if (howMany <= batch)
- {
- howMany++;
- System.out.println("Задержка "+delayevery/1000+" секунд");
- Thread.sleep(delayevery);
- }
- else
- {
- howMany = 0;
- System.out.println("Задержка "+delaybatch/1000+" секунд");
- Thread.sleep(delaybatch);
- }
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress(username,alias));
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse(touser));
- message.setSubject(subject);
- // Create the message part
- BodyPart messageBodyPart = new MimeBodyPart();
- BodyPart imagePart = new MimeBodyPart();
- if (image != "")
- imagePart.setContent("<img src=""+image+"">","text/html");
- // Now set the actual message
- messageBodyPart.setText(MailSender.message);
- // Create a multipar message
- Multipart multipart = new MimeMultipart();
- //Set image message part
- multipart.addBodyPart(imagePart);
- // Set text message part
- multipart.addBodyPart(messageBodyPart);
- // Part two is attachment
- messageBodyPart = new MimeBodyPart();
- if (attaching != "")
- {
- DataSource source = new FileDataSource(attaching);
- messageBodyPart.setDataHandler(new DataHandler(source));
- messageBodyPart.setFileName(javax.mail.internet.MimeUtility.encodeWord(source.getName(),
- "UTF-8", null));
- multipart.addBodyPart(messageBodyPart);
- }
- // Send the complete message parts
- message.setContent(multipart);
- Transport.send(message);
- System.out.println("Done "+(++counter));
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- } catch (UnsupportedEncodingException ex) {
- Logger.getLogger(MailSender.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- } catch (FileNotFoundException ex) {
- System.out.print("База была не найдена.");
- } catch (InterruptedException ex) {
- System.out.print("Что-то неверно.");
- }
- props.put("mail.smtp.ssl.enable", "true");
Add Comment
Please, Sign In to add comment