Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.util.Random;
- import java.util.concurrent.TimeUnit;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.openqa.selenium.Alert;
- import org.openqa.selenium.By;
- import org.openqa.selenium.Keys;
- import org.openqa.selenium.UnhandledAlertException;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.WebDriverWait;
- public class MassEmailTool {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- /*
- =======================================
- Credentials
- =======================================
- String CUsername = "something";
- String CPassword = "something";
- =======================================
- ======================================
- Email Info
- ======================================
- String ESubject = "email subject";
- // String EMessage = "Message is a message =D";
- =======================================*/
- String currentDir = System.getProperty("user.dir");
- String marionetteDriverLocation = currentDir + "/chromedriver.exe";
- System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
- WebDriver driver = new ChromeDriver();
- String pageLink = "https://accounts.google.com/ServiceLogin?service=mail#identifier";
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- // Connect To GMAIL
- driver.get(pageLink);
- int excelRow = 1;
- int excelSchoolColumn = 0;
- int excelEmailColumn = 4;
- int excelStatusColumn = 5;
- String emailPrint;
- boolean valid = false;
- // String pageCode = driver.getPageSource();
- // System.out.println(pageCode);
- try {
- WebElement userName = (new WebDriverWait(driver, 10))
- .until(ExpectedConditions.visibilityOfElementLocated(By.id("Email")));
- // Email Address/Username
- userName.sendKeys("javatestingchucknorris@gmail.com");
- driver.findElement(By.id("next")).click();
- Thread.sleep(2 * 5000);
- WebElement passWord = (new WebDriverWait(driver, 10))
- .until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
- // Password
- passWord.sendKeys("GradeAUnderA");
- // Press Sign In
- driver.findElement(By.id("signIn")).click();
- Thread.sleep(2 * 1000);
- // pageCode = driver.getPageSource();
- String composeLink = driver.getCurrentUrl();
- for (int xx = 300; xx > 200; xx--) {
- InputStream inp = new FileInputStream("wb.xls");
- HSSFWorkbook wb = new HSSFWorkbook(inp);
- HSSFSheet sheet = wb.getSheetAt(0);
- Row row = sheet.getRow(excelRow);
- Cell school = row.getCell(excelSchoolColumn);
- Cell done = row.createCell(excelStatusColumn);
- // Modify the cellContents here
- // Write the output to a file
- Cell email = row.getCell(excelEmailColumn);
- if (email == null) {
- emailPrint = "No Email";
- done.setCellValue("No Email");
- valid = false;
- System.out.println(school.toString() + "\n" + emailPrint + "\nNot Sent\n----------------------");
- } else {
- valid = true;
- emailPrint = email.toString();
- }
- String cntrlB = Keys.chord(Keys.CONTROL, "b");
- String EMessage = "Dear " + school.toString() + "\n" + "\n"
- + "We know that our teachers are passionate and are always looking for ways to bring out the best in our students. At S.T.A.R. Maths Online, we've built our software to assist our teachers in doing just that!"
- + "\n" + "\n"
- + "S.T.A.R Maths Online was built to create a fun and interactive environment for kids to learn Maths as well as alleviate some of the administrative burdens on our teachers."
- + "\n" + "\n"
- + "Our vision is to build an amazing software that would bring out the best in our students and a powerful tool for teachers to manage their classes."
- + "\n" + "\n" + cntrlB + "How do we benefit the kids?" + cntrlB
- + "– A fun and interactive learning environment where students will enjoy spending time learning Maths."
- + "– As students progress and excel, S.T.A.R Maths Online will automatically increase the level of difficulty to match their potential."
- + "– When students are having difficulties with certain concepts, our software will set the questions to be easier ensuring that their gaps are filled before they progress."
- + "\n" + "\n" + cntrlB + "How do we benefit the teachers?" + cntrlB
- + "– S.T.A.R. Maths Online follows the NSW curriculum guidelines set out by the board of studies."
- + "– A powerful and easy tool to plan out the year’s homework schedule while having the flexibility to adjust the teaching program weekly."
- + "– All questions completed by students are automatically marked and results are fed back live to your login."
- + "– An option to request questions to be added to S.T.A.R Maths Online tailored to a concept you have taught in class."
- + "– Full reports of results throughout the year to ensure that no information is missed."
- + "\n" + "\n" + cntrlB + "How do we benefit the parents?" + cntrlB
- + "– A parent’s portal to ensure parents are part of their child’s educational journey!" + "\n"
- + "\n"
- + "We firmly believe that classroom teaching supplemented by computerised education can bring out the best of every student and reduce the amount of time teachers spend on administration."
- + "\n" + "\n"
- + "As part of our pilot launch of S.T.A.R. Maths Online, we will be providing teachers and schools with free access over the next year starting from term three 2016!"
- + "\n" + "\n" + "https://starmathsonline.com.au/register/" + "\n" + "\n"
- + "If your school would like to see a demo of our innovative software before trialling, please let us know and we are more than happy to visit your school and conduct a demo.";
- Random randomGenerator = new Random();
- if (valid == true) {
- Thread.sleep(2 * 1000);
- driver.findElement(By.xpath("//div[@role=\"button\" and text()=\"COMPOSE\"]")).click();
- String sendTo = "javatestingtomcruise@gmail.com";
- try {
- WebElement receiver = (new WebDriverWait(driver, 10))
- .until(ExpectedConditions.visibilityOfElementLocated(By.name("to")));
- receiver.sendKeys(sendTo);
- } catch (UnhandledAlertException eee) {
- Alert alert = driver.switchTo().alert();
- alert.accept();
- WebElement receiver = (new WebDriverWait(driver, 10))
- .until(ExpectedConditions.visibilityOfElementLocated(By.name("to")));
- receiver.sendKeys(sendTo);
- }
- // TO
- int randomMessage = randomGenerator.nextInt(1000000000) + 50000;
- WebElement subjecto = (new WebDriverWait(driver, 10))
- .until(ExpectedConditions.visibilityOfElementLocated(By.name("subjectbox")));
- // Subject
- subjecto.sendKeys(xx + " " + school.toString());
- WebElement message = (new WebDriverWait(driver, 10)).until(ExpectedConditions
- .visibilityOfElementLocated(By.xpath("//div[@aria-label=\"Message Body\"]")));
- randomMessage = randomGenerator.nextInt(1000000000) + 500000;
- // Message
- message.sendKeys(EMessage + "\n " + email + randomMessage);
- int randomInt = randomGenerator.nextInt(11) + 4;
- Thread.sleep(randomInt * 1000);
- // Send Mail
- String keysPressed = Keys.chord(Keys.CONTROL, Keys.RETURN);
- message.sendKeys(keysPressed);
- FileOutputStream fileOut = new FileOutputStream("wb.xls");
- done.setCellValue("Email Sent");
- wb.write(fileOut);
- fileOut.close();
- excelRow++;
- System.out.println(school.toString() + "\n" + emailPrint + "\nSent\n----------------------");
- }
- if (valid == false) {
- FileOutputStream fileOut = new FileOutputStream("wb.xls");
- done.setCellValue("Email Not Sent");
- wb.write(fileOut);
- fileOut.close();
- excelRow++;
- }
- }
- } catch (Exception e) {
- System.out.println("Error");
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement