Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mail.GabeEmail;
- import mail.Gmail;
- import javax.mail.MessagingException;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Scanner;
- public class Launcher {
- public static void main(String[] args) throws SQLException, ClassNotFoundException, FileNotFoundException, InterruptedException {
- JDBC sql = new JDBC("//localhost/student_data", "root", "");
- sql.connect();
- int start = 0;
- int limit = 20;
- int emailCount = 0;
- ResultSet rowCount = sql.executeQuery("SELECT COUNT(*) FROM `accounts`");
- rowCount.next();
- int rowNumb = rowCount.getInt(1);
- while(start < rowNumb+15) {
- System.out.println("Starting");
- ResultSet targets = sql.executeQuery("SELECT `email` FROM `accounts` LIMIT " + start + "," + limit);
- StringBuilder recipients = new StringBuilder();
- while (targets.next()) {
- recipients.append(targets.getString(1) + ",");
- }
- ResultSet resultSet = sql.executeQuery(buildQuery());
- while (resultSet.next()) {
- System.out.println("Sending to: " + recipients);
- String user = resultSet.getString(1);
- String pass = resultSet.getString(2);
- new Thread(() -> {
- Gmail gmail = new Gmail(user, pass);
- gmail.init();
- try {
- gmail.sendMessage(new GabeEmail(recipients.toString()));
- System.out.println("Email sent successfully!");
- } catch (MessagingException e) {
- System.out.println("Email failure!" + "User: " + user + " Password: " + pass);
- e.printStackTrace();
- }
- }).start();
- emailCount = emailCount + 1;
- System.out.println("Index: " + emailCount);
- Thread.sleep(1000);
- }
- start += limit;
- }
- sql.close();
- }
- private static String buildQuery() throws FileNotFoundException {
- StringBuilder query = new StringBuilder("SELECT `email`, `password` FROM `accounts` WHERE ");
- Scanner scanner = new Scanner(new File(System.getProperty("user.dir") + "/acc.txt"));
- while(scanner.hasNextLine())
- query.append("email='").append(scanner.nextLine()).append("' OR ");
- return query.toString().substring(0, query.length()-4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement