daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jun 8th, 2017 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import mail.GabeEmail;
  2. import mail.Gmail;
  3.  
  4. import javax.mail.MessagingException;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.util.Scanner;
  10.  
  11. public class Launcher {
  12.  
  13.     public static void main(String[] args) throws SQLException, ClassNotFoundException, FileNotFoundException, InterruptedException {
  14.         JDBC sql = new JDBC("//localhost/student_data", "root", "");
  15.  
  16.         sql.connect();
  17.         int start = 0;
  18.         int limit = 20;
  19.         int emailCount = 0;
  20.  
  21.         ResultSet rowCount = sql.executeQuery("SELECT COUNT(*) FROM `accounts`");
  22.         rowCount.next();
  23.         int rowNumb = rowCount.getInt(1);
  24.  
  25.         while(start < rowNumb+15) {
  26.             System.out.println("Starting");
  27.             ResultSet targets = sql.executeQuery("SELECT `email` FROM `accounts` LIMIT " + start + "," + limit);
  28.             StringBuilder recipients = new StringBuilder();
  29.             while (targets.next()) {
  30.                 recipients.append(targets.getString(1) + ",");
  31.             }
  32.  
  33.             ResultSet resultSet = sql.executeQuery(buildQuery());
  34.             while (resultSet.next()) {
  35.                 System.out.println("Sending to: " + recipients);
  36.                 String user = resultSet.getString(1);
  37.                 String pass = resultSet.getString(2);
  38.                 new Thread(() -> {
  39.                     Gmail gmail = new Gmail(user, pass);
  40.                     gmail.init();
  41.                     try {
  42.                         gmail.sendMessage(new GabeEmail(recipients.toString()));
  43.                         System.out.println("Email sent successfully!");
  44.                     } catch (MessagingException e) {
  45.                         System.out.println("Email failure!" + "User: " + user + " Password: " + pass);
  46.                         e.printStackTrace();
  47.                     }
  48.  
  49.                 }).start();
  50.                 emailCount = emailCount + 1;
  51.                 System.out.println("Index: " + emailCount);
  52.                 Thread.sleep(1000);
  53.             }
  54.             start += limit;
  55.         }
  56.         sql.close();
  57.     }
  58.  
  59.     private static String buildQuery() throws FileNotFoundException {
  60.         StringBuilder query = new StringBuilder("SELECT `email`, `password` FROM `accounts` WHERE ");
  61.         Scanner scanner = new Scanner(new File(System.getProperty("user.dir") + "/acc.txt"));
  62.         while(scanner.hasNextLine())
  63.             query.append("email='").append(scanner.nextLine()).append("' OR ");
  64.  
  65.         return query.toString().substring(0, query.length()-4);
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top