I have my selenium test send an email whenever there is an error, this is hard coded into my test however I am looking to see if it is possible to call it from an external file so I can just edit the Email file instead of having to go into the code and change it.
The way i'm getting it to email is
try {
}
catch (Exception e) {
e.printStackTrace();
new SendMail("senderemail","reciveremail",e); }
}
Which calls it directly from:
public SendMail(String fromMail,String tomail, Exception e ) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("xxxxxxx","xxxxxx");
Question: How can I get my selenium to get a list from an external file of emails to send them out?
Edit: Updated code of what finally works.
String fileName = "/Users/cdolan/Desktop/liness.txt";
String Email = "";
try(BufferedReader br = new BufferedReader(new FileReader(fileName)) {
while ((Email = br.readLine()) !=null) {
<Test code here goes here>
}
}
catch(Exception e) {
e.printStackTrace();
new SendMail("email123@gmail.com",Email,e); }
}