grach

MailSenderWithDelay

Jul 19th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.IOException;
  3. import java.nio.file.Files;
  4. import java.nio.file.Path;
  5. import javax.mail.*;
  6. import javax.mail.internet.*;
  7. import java.io.File;
  8. import java.util.Scanner;
  9. import java.io.IOException;
  10. import java.nio.file.Files;
  11. import java.nio.file.Path;
  12.  
  13.  
  14.  
  15. public class EmailSenderFromFile {
  16.     public static void main(String[] args) throws IOException, InterruptedException {
  17.         Scanner scan = new Scanner(System.in);
  18.  
  19.         Path fileName = Path.of("D:/JavaBasicBabyBeginner/NestedConditionalStatment/Java-Fundamentals-May-2020/11 Arrays Exercise/src/emailText2.txt");
  20.  
  21.         Files.readString(fileName);
  22.         // String actual = Files.readString(fileName);
  23.         Files.readString(fileName);
  24.         //String actual = Files.readString(fileName);
  25.         List<String> stringList = Files.readAllLines(fileName);
  26.  
  27.  
  28.         String importantInfo[] = stringList.toArray(new String[]{});
  29.  
  30.         for (int i = 0;
  31.              i < importantInfo.length;
  32.              i++) {
  33.             //Pause for 4 seconds
  34.             Thread.sleep(9000);
  35.             //Print a message
  36.             System.out.println(importantInfo[i]);
  37.             System.out.println(9000);
  38.  
  39.  
  40.             final String username = "rado****@******.com";  // like [email protected]
  41.             final String password = "***********";   // password here
  42.  
  43.             Properties props = new Properties();
  44.             props.put("mail.smtp.auth", "true");
  45.             props.put("mail.smtp.starttls.enable", "true");
  46.             props.put("mail.smtp.host", "smtp-mail.outlook.com");
  47.  
  48.             props.put("mail.smtp.port", "587");
  49.  
  50.             Session session = Session.getInstance(props,
  51.                     new javax.mail.Authenticator() {
  52.                         @Override
  53.                         protected PasswordAuthentication getPasswordAuthentication() {
  54.                             return new PasswordAuthentication(username, password);
  55.                         }
  56.                     });
  57.             session.setDebug(true);
  58.  
  59.             try {
  60.  
  61.                 Message message = new MimeMessage(session);
  62.                 message.setFrom(new InternetAddress(username));
  63.  
  64.  
  65.                 message.addRecipients(Message.RecipientType.BCC,
  66.                           InternetAddress.parse((importantInfo[i])));   // like [email protected]
  67.                 message.setSubject("90000 Samo za proba BCC");
  68.                 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");
  69.  
  70.                 Transport.send(message);
  71.  
  72.                 System.out.println("Done");
  73.  
  74.             } catch (MessagingException e) {
  75.                 throw new RuntimeException(e);
  76.             }
  77.         }
  78.     }
  79. }
Add Comment
Please, Sign In to add comment