Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import javax.mail.*;
- import javax.mail.internet.*;
- import java.io.File;
- import java.util.Scanner;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.util.concurrent.ThreadLocalRandom;
- import java.util.Random;
- public class EmailSenderFromFile {
- public static void main(String[] args) throws IOException, InterruptedException {
- Scanner scan = new Scanner(System.in);
- Path fileName = Path.of("D:/JavaBasicBabyBeginner/NestedConditionalStatment/Java-Fundamentals-May-2020/11 Arrays Exercise/src/emailText2.txt");
- Files.readString(fileName);
- // String actual = Files.readString(fileName);
- Files.readString(fileName);
- //String actual = Files.readString(fileName);
- List<String> stringList = Files.readAllLines(fileName);
- String importantInfo[] = stringList.toArray(new String[]{});
- Random rand = new Random();
- int min = 600000;
- int max = 1560000;
- for (int i = 0; i < importantInfo.length;i++) {
- int delay = rand.nextInt((max - min) + 1) + min;
- //Pause for 4 seconds
- Thread.sleep(delay);
- //Print a message
- System.out.println(importantInfo[i]);
- int minutes = delay/60000;
- System.out.println("Delay EMAIL with= "+ minutes + " minutes" );
- final String password = "*******"; // password here
- Properties props = new Properties();
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", "smtp-mail.outlook.com");
- props.put("mail.smtp.port", "587");
- Session session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- session.setDebug(true);
- try {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress(username));
- message.addRecipients(Message.RecipientType.BCC,
- message.setSubject("90000 Samo za proba BCC");
- message.setText("Hello, this is example of sending Java email with 90000 milliseconds delay , message should be deleted, you can't see the sender list");
- Transport.send(message);
- System.out.println("Done");
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment