Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.28 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileOutputStream;
  3. import java.io.InputStream;
  4. import java.util.Random;
  5. import java.util.concurrent.TimeUnit;
  6. import org.apache.poi.hssf.usermodel.HSSFSheet;
  7. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  8. import org.apache.poi.ss.usermodel.Cell;
  9. import org.apache.poi.ss.usermodel.Row;
  10. import org.openqa.selenium.Alert;
  11. import org.openqa.selenium.By;
  12. import org.openqa.selenium.Keys;
  13. import org.openqa.selenium.UnhandledAlertException;
  14. import org.openqa.selenium.WebDriver;
  15. import org.openqa.selenium.WebElement;
  16. import org.openqa.selenium.chrome.ChromeDriver;
  17. import org.openqa.selenium.support.ui.ExpectedConditions;
  18. import org.openqa.selenium.support.ui.WebDriverWait;
  19.  
  20. public class MassEmailTool {
  21.  
  22. public static void main(String[] args) {
  23. // TODO Auto-generated method stub
  24.  
  25. /*
  26. =======================================
  27. Credentials
  28. =======================================
  29. String CUsername = "something";
  30. String CPassword = "something";
  31. =======================================
  32.  
  33.  
  34. ======================================
  35. Email Info
  36. ======================================
  37. String ESubject = "email subject";
  38. // String EMessage = "Message is a message =D";
  39. =======================================*/
  40.  
  41. String currentDir = System.getProperty("user.dir");
  42. String marionetteDriverLocation = currentDir + "/chromedriver.exe";
  43. System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
  44. WebDriver driver = new ChromeDriver();
  45.  
  46. String pageLink = "https://accounts.google.com/ServiceLogin?service=mail#identifier";
  47.  
  48. driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  49.  
  50. // Connect To GMAIL
  51. driver.get(pageLink);
  52.  
  53. int excelRow = 1;
  54. int excelSchoolColumn = 0;
  55. int excelEmailColumn = 4;
  56. int excelStatusColumn = 5;
  57. String emailPrint;
  58. boolean valid = false;
  59.  
  60. // String pageCode = driver.getPageSource();
  61. // System.out.println(pageCode);
  62.  
  63. try {
  64. WebElement userName = (new WebDriverWait(driver, 10))
  65. .until(ExpectedConditions.visibilityOfElementLocated(By.id("Email")));
  66.  
  67. // Email Address/Username
  68. userName.sendKeys("javatestingchucknorris@gmail.com");
  69.  
  70. driver.findElement(By.id("next")).click();
  71. Thread.sleep(2 * 5000);
  72.  
  73. WebElement passWord = (new WebDriverWait(driver, 10))
  74. .until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
  75.  
  76. // Password
  77. passWord.sendKeys("GradeAUnderA");
  78.  
  79. // Press Sign In
  80. driver.findElement(By.id("signIn")).click();
  81.  
  82. Thread.sleep(2 * 1000);
  83. // pageCode = driver.getPageSource();
  84.  
  85. String composeLink = driver.getCurrentUrl();
  86.  
  87. for (int xx = 300; xx > 200; xx--) {
  88.  
  89. InputStream inp = new FileInputStream("wb.xls");
  90. HSSFWorkbook wb = new HSSFWorkbook(inp);
  91. HSSFSheet sheet = wb.getSheetAt(0);
  92. Row row = sheet.getRow(excelRow);
  93. Cell school = row.getCell(excelSchoolColumn);
  94. Cell done = row.createCell(excelStatusColumn);
  95.  
  96. // Modify the cellContents here
  97. // Write the output to a file
  98.  
  99. Cell email = row.getCell(excelEmailColumn);
  100. if (email == null) {
  101. emailPrint = "No Email";
  102. done.setCellValue("No Email");
  103. valid = false;
  104.  
  105. System.out.println(school.toString() + "\n" + emailPrint + "\nNot Sent\n----------------------");
  106.  
  107. } else {
  108. valid = true;
  109. emailPrint = email.toString();
  110.  
  111. }
  112.  
  113. String cntrlB = Keys.chord(Keys.CONTROL, "b");
  114.  
  115. String EMessage = "Dear " + school.toString() + "\n" + "\n"
  116. + "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!"
  117. + "\n" + "\n"
  118. + "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."
  119. + "\n" + "\n"
  120. + "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."
  121. + "\n" + "\n" + cntrlB + "How do we benefit the kids?" + cntrlB
  122. + "– A fun and interactive learning environment where students will enjoy spending time learning Maths."
  123. + "– As students progress and excel, S.T.A.R Maths Online will automatically increase the level of difficulty to match their potential."
  124. + "– 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."
  125. + "\n" + "\n" + cntrlB + "How do we benefit the teachers?" + cntrlB
  126. + "– S.T.A.R. Maths Online follows the NSW curriculum guidelines set out by the board of studies."
  127. + "– A powerful and easy tool to plan out the year’s homework schedule while having the flexibility to adjust the teaching program weekly."
  128. + "– All questions completed by students are automatically marked and results are fed back live to your login."
  129. + "– An option to request questions to be added to S.T.A.R Maths Online tailored to a concept you have taught in class."
  130. + "– Full reports of results throughout the year to ensure that no information is missed."
  131. + "\n" + "\n" + cntrlB + "How do we benefit the parents?" + cntrlB
  132. + "– A parent’s portal to ensure parents are part of their child’s educational journey!" + "\n"
  133. + "\n"
  134. + "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."
  135. + "\n" + "\n"
  136. + "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!"
  137. + "\n" + "\n" + "https://starmathsonline.com.au/register/" + "\n" + "\n"
  138. + "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.";
  139.  
  140. Random randomGenerator = new Random();
  141.  
  142. if (valid == true) {
  143.  
  144. Thread.sleep(2 * 1000);
  145.  
  146. driver.findElement(By.xpath("//div[@role=\"button\" and text()=\"COMPOSE\"]")).click();
  147.  
  148. String sendTo = "javatestingtomcruise@gmail.com";
  149. try {
  150. WebElement receiver = (new WebDriverWait(driver, 10))
  151. .until(ExpectedConditions.visibilityOfElementLocated(By.name("to")));
  152. receiver.sendKeys(sendTo);
  153. } catch (UnhandledAlertException eee) {
  154.  
  155. Alert alert = driver.switchTo().alert();
  156. alert.accept();
  157. WebElement receiver = (new WebDriverWait(driver, 10))
  158. .until(ExpectedConditions.visibilityOfElementLocated(By.name("to")));
  159. receiver.sendKeys(sendTo);
  160.  
  161. }
  162. // TO
  163.  
  164. int randomMessage = randomGenerator.nextInt(1000000000) + 50000;
  165.  
  166. WebElement subjecto = (new WebDriverWait(driver, 10))
  167. .until(ExpectedConditions.visibilityOfElementLocated(By.name("subjectbox")));
  168.  
  169. // Subject
  170. subjecto.sendKeys(xx + " " + school.toString());
  171.  
  172. WebElement message = (new WebDriverWait(driver, 10)).until(ExpectedConditions
  173. .visibilityOfElementLocated(By.xpath("//div[@aria-label=\"Message Body\"]")));
  174.  
  175. randomMessage = randomGenerator.nextInt(1000000000) + 500000;
  176.  
  177. // Message
  178. message.sendKeys(EMessage + "\n " + email + randomMessage);
  179.  
  180. int randomInt = randomGenerator.nextInt(11) + 4;
  181.  
  182. Thread.sleep(randomInt * 1000);
  183.  
  184. // Send Mail
  185. String keysPressed = Keys.chord(Keys.CONTROL, Keys.RETURN);
  186.  
  187. message.sendKeys(keysPressed);
  188.  
  189. FileOutputStream fileOut = new FileOutputStream("wb.xls");
  190. done.setCellValue("Email Sent");
  191. wb.write(fileOut);
  192. fileOut.close();
  193. excelRow++;
  194.  
  195. System.out.println(school.toString() + "\n" + emailPrint + "\nSent\n----------------------");
  196.  
  197. }
  198. if (valid == false) {
  199. FileOutputStream fileOut = new FileOutputStream("wb.xls");
  200. done.setCellValue("Email Not Sent");
  201. wb.write(fileOut);
  202. fileOut.close();
  203. excelRow++;
  204. }
  205. }
  206.  
  207. } catch (Exception e) {
  208. System.out.println("Error");
  209. System.out.println(e);
  210.  
  211. }
  212.  
  213. }
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement