Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
rodale_janet
Active particpant
Active particpant
Posts : 10
Join date : 2014-03-07

Automate sending an email in Selenium IDE Empty Automate sending an email in Selenium IDE

Fri Mar 07, 2014 10:49 pm
Can you send an email with the results file attached from Selenium itself or do you need to do it another way.  I have VBS code that I can modify to send an email with an attachment just do not know how to get it to execute.   Thanks!!
Advisor
Advisor
------------------------
------------------------
Posts : 387
Join date : 2009-07-30
Location : India
https://seleniumforum.forumotion.net

Automate sending an email in Selenium IDE Empty Re: Automate sending an email in Selenium IDE

Tue Jun 24, 2014 5:26 pm
HI,
 you can do it in 2 ways:

1. write the same logic of VBscript in your selenium scripting language.
2. find a way to execute a .vbs or batch file via selenium programming.

choose the either way to get a solution. google it for exact snippet.
avatar
rodale_janet
Active particpant
Active particpant
Posts : 10
Join date : 2014-03-07

Automate sending an email in Selenium IDE Empty Re: Automate sending an email in Selenium IDE

Tue Jun 24, 2014 7:09 pm
Thanks!!

I actually found something on the internet that supplied code to do it in Java.   I have a "SendMail" class that I execute if there is an error or if the test completes successfully.
avatar
saravana.s
Posts : 2
Join date : 2014-06-27

Automate sending an email in Selenium IDE Empty Re: Automate sending an email in Selenium IDE

Fri Jun 27, 2014 6:28 pm
Thanks for sharing good information. Keep posting
avatar
rodale_janet
Active particpant
Active particpant
Posts : 10
Join date : 2014-03-07

Automate sending an email in Selenium IDE Empty Re: Automate sending an email in Selenium IDE

Fri Jun 27, 2014 6:36 pm
Code:
Here is the code that I found and am using.  You need to bring in the JavaMail library to your project.:
package [name of your package];

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.activation.*;

public class SendMail {
   public SendMail(String[] toMail, String subject, String msg) {
          Properties props = System.getProperties();
          props.put("mail.smtp.host", "smtp.rodale.com");
          props.put("mail.smtp.port", "25");
          Session session = Session.getDefaultInstance(props);
          try {
              Message message = new MimeMessage(session);
              message.setFrom(new InternetAddress("TestAutomation@rodale.com"));
              InternetAddress[] toAddress = new InternetAddress[toMail.length];

              for( int i = 0; i < toMail.length; i++ ) {
                   toAddress[i] = new InternetAddress(toMail[i]);
               }

               for( int i = 0; i < toAddress.length; i++) {
                   message.addRecipient(Message.RecipientType.TO, toAddress[i]);
               }

              message.setSubject(subject);
              message.setText(msg);
              Transport.send(message);
              System.out.println("Done");
          }
          catch (MessagingException ex) {
              throw new RuntimeException(ex);
          }
         
   }

}

This is how my code uses it:
private void executeSubXpath (String urlName, String menuItem, String pageTitle)
   {
      String msg = "";
                  
      wait_fiveSeconds();
      try
       {
          WebElement subElement = driver.findElement(By.id(menuItem));
          String urlLink = subElement.getAttribute("href");
          JavascriptExecutor js = (JavascriptExecutor) driver;
         
            
          System.out.println(urlLink);
         wait_fiveSeconds();
         js.executeScript("arguments[0].setAttribute('target', arguments[1]);", subElement, "_self");
         js.executeScript("arguments[0].click();", subElement);
           wait_fiveSeconds();
          checkUrl(urlName, pageTitle, urlLink);
       }
      
       catch (Exception e)
       {
          System.out.println(e);
          msg = urlName + " test was not successful" +
                System.getProperty("line.separator") + System.getProperty("line.separator") + e;
          new SendMail(to_email,urlName,msg);
          errorsFound = true;
          driver.navigate().to(baseUrl);
       }
       wait_fiveSeconds();
   }
Sponsored content

Automate sending an email in Selenium IDE Empty Re: Automate sending an email in Selenium IDE

Back to top
Permissions in this forum:
You cannot reply to topics in this forum