Sahi Documentation

Email related issues

sendEmail fails for Microsoft Outlook with Permission denied: connect error

symptom When sending an email from my outlook server using sendEmail, I keep getting a connect error. (101145)
ERROR [110 ms] [11:40:53.546]
Wrapped javax.mail.MessagingException: Could not connect to SMTP host:, port: 25;
nested exception is: Permission denied: connect

The code for sendEmail is as follows.
function sendEmail($emailSubject, $emailBody) {
      var $host = "";
      var $port = 25;
      var $username = "";
      var $password = "";
      var $isSSL = false; // set to true if you use SSL
      var $mailer = new$host, $port, $username, $password, $isSSL);
      var $from = "";
      var $to = "";
      $mailer.send($from, $to, $emailSubject, $emailBody);

sendEmail("Mail from Sahi", "Script Run");

We do not need authentication and the server can be connected via telnet.
  1. Verify that all the values used in sendEmail are correct.
  2. There is an issue with Java 1.7 which may cause this problem.

    Please try the following.
    1. Take a backup of bin\dashboard.bat.
    2. Edit dashboard.bat. Replace this line
      java -classpath %SAHI_EXT_CLASS_PATH%;%SAHI_CLASS_PATH% net.sf.sahi.ui.Dashboard "%SAHI_HOME%" "%SAHI_USERDATA_DIR_TMP%"
      java -classpath %SAHI_EXT_CLASS_PATH%;%SAHI_CLASS_PATH% net.sf.sahi.ui.Dashboard "%SAHI_HOME%" "%SAHI_USERDATA_DIR_TMP%"

      We have added
    3. Restart Sahi by launching start_dashboard.bat
    4. Check if you are able to send email.
  3. If this does NOT work, try the following too. Here we are forcing Sahi to use an older version of Java - either 1.5.x or 1.6.x.
    1. Revert changes to dashboard.bat that you did in the above steps.
    2. Take a backup of userdata\bin\setjava.bat.
    3. Edit setjava.bat. Change the value of SAHI_JAVA_HOME to point to a lesser JRE version, may be 1.6.
    4. Restart Sahi by launching start_dashboard.bat
    5. Check if you are able to send email