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 = "bhavin@acetuitioncentre.com.au";
- String CPassword = "Star2016";
- // =======================================
- // =======================================
- // Tool Settings
- // =======================================
- int SEmailsToBeSent = 100;
- int SStartFrom = 1;
- // =======================================
- /**
- Setting Up Selenium
- **/
- String currentDir = System.getProperty("user.dir");
- String marionetteDriverLocation = currentDir + "/chromedriver.exe";
- System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
- WebDriver driver = new ChromeDriver();
- /**
- Gmail Link
- **/
- String pageLink = "https://accounts.google.com/ServiceLogin?service=mail#identifier";
- driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
- // Connect To GMAIL
- driver.get(pageLink);
- // =======================================
- // Excel Settings | A = 0, B = 1 and so on
- // =======================================
- int excelRow = 1;
- int excelSchoolColumn = 0;
- int excelEmailColumn = 4;
- int excelStatusColumn = 5;
- String emailPrint;
- boolean valid = false;
- // =======================================
- try {
- // Enter Email Address/Username
- WebElement userName = (new WebDriverWait(driver, 10))
- .until(ExpectedConditions.visibilityOfElementLocated(By.id("Email")));
- userName.sendKeys(CUsername);
- // Click Next
- driver.findElement(By.id("next")).click();
- Thread.sleep(2 * 5000);
- // Enter Password
- WebElement passWord = (new WebDriverWait(driver, 10))
- .until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
- passWord.sendKeys(CPassword);
- // Press Sign In
- driver.findElement(By.id("signIn")).click();
- Thread.sleep(2 * 1000);
- for (int xx = SEmailsToBeSent; xx > 0; xx--) {
- //Locating Data using Excel Settings
- 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);
- Cell email = row.getCell(excelEmailColumn);
- //Checking if the email exists
- 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();
- }
- //Setting up a keyboard shortcut
- String cntrlB = Keys.chord(Keys.CONTROL, "b");
- // =======================================
- // Email Settings
- // =======================================
- String ESubject = school.toString();
- String EMessage = "Dear " + school.toString() + ",\n" + "\n"
- + "Over the past year, we’ve reached out to a selected number of schools, both public and private to use our primary math software. With all the feedback provided by all the teachers that has seen our software improved by leaps and bounds in the way our software can help teachers bring out the best in their children."
- + "To continue our passion and commitment to help all teachers out there, we are now making S.T.A.R. Maths Online free for everyone to use!"
- + "\n"
- + cntrlB + "Our innovative software will allow all teachers to:" + cntrlB
- + "- Create unlimited online math accounts for all their children."
- + "- A simple and intuitive year planner to assist teachers with supplementary homework to reinforce what was learnt in class."
- + "- Unlimited NAPLAN practice questions for years 3 & 5!"
- + "- Robust NAPLAN and progress reports throughout the year so that you are always informed of your children’s progress."
- + "- We follow the Australian Curriculum guidelines set out by the Board of Studies."
- + "- Link parents to their child’s account to view their results throughout the year."
- + "If you think this software can assist any teachers at (School’s name), please forward this email to them as registration and usage of our innovative software are free!"
- + "- A link to our website and registration page are as per below:
- Website: http://starmathsonline.com.au/
- Registration: https://teacher.starmathsonline.com.au/Account/Register
- We understand what it takes to be a teacher and we’re here to help!
- + "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 number generator code
- Random randomGenerator = new Random();
- //If Email exists
- if (valid == true) {
- Thread.sleep(2 * 1000);
- //Click "Compose" Button
- driver.findElement(By.xpath("//div[@role=\"button\" and text()=\"COMPOSE\"]")).click();
- //Type the school's email address
- String sendTo = "javatestingtomcruise@gmail.com";
- //A code to counter gmail's bot detector
- 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);
- }
- // Subject
- WebElement subjecto = (new WebDriverWait(driver, 10))
- .until(ExpectedConditions.visibilityOfElementLocated(By.name("subjectbox")));
- subjecto.sendKeys(ESubject);
- // Message
- WebElement message = (new WebDriverWait(driver, 10)).until(ExpectedConditions
- .visibilityOfElementLocated(By.xpath("//div[@aria-label=\"Message Body\"]")));
- message.sendKeys(EMessage + "\n " + email);
- //Random intervals between each emails
- int randomInt = randomGenerator.nextInt(11) + 4;
- Thread.sleep(randomInt * 1000);
- // Send Mail (Press Enter)
- String keysPressed = Keys.chord(Keys.CONTROL, Keys.RETURN);
- message.sendKeys(keysPressed);
- //Update The Excel File
- 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 email wasn't found
- if (valid == false) {
- //Update The Excel File
- FileOutputStream fileOut = new FileOutputStream("wb.xls");
- done.setCellValue("Email Not Sent");
- wb.write(fileOut);
- fileOut.close();
- excelRow++;
- }
- }
- //Errors collector
- } catch (Exception e) {
- System.out.println("Error");
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement