Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, windows and java based applications. Get your 30 day free trial.

Discuss your Sahi Pro usage patterns, best practices, problems and solutions. Help others solve their problems and seek help from the community when needed. If you need specific support on your application, please email support @ sahipro.com

Sahi Pro 610 - Email Sending Does not work with username password is null or empty

Sahi Pro 610 - Email Sending Does not work with username password is null or empty


I am just adding solution to the above problem, till Sahi Pro 601 we were able to send email using our local mailhost without any password.

But in Sahi Pro 610 the below code does not work is the username and password are empty or null.
http://sahipro.com/docs/using-sahi/sending-emails.html

To make things work as mentioned in the above link, make sure you modify the dashboard.bat file present in the sahi_pro_home\bin folder


::set SAHI_CLASS_PATH=%SAHI_HOME%\lib\sahi.jar;%SAHI_HOME%\extlib\rhino\js.jar;%SAHI_HOME%\extlib\apc\commons-codec-1.3.jar;%SAHI_HOME%\extlib\db\h2.jar;%SAHI_HOME%\extlib\license\truelicense.jar;%SAHI_HOME%\extlib\license\truexml.jar;%POI_JARS%;%JAVAX_MAIL_JARS%;%C3P0_JARS%;%APPLET_JARS%;

set SAHI_CLASS_PATH=%SAHI_HOME%\lib\ant-sahi.jar;%SAHI_HOME%\lib\sahi.jar;%SAHI_HOME%\extlib\rhino\js.jar;%SAHI_HOME%\extlib\apc\commons-codec-1.3.jar;%SAHI_HOME%\extlib\db\h2.jar;%SAHI_HOME%\extlib\license\truelicense.jar;%SAHI_HOME%\extlib\license\truexml.jar;%POI_JARS%;%JAVAX_MAIL_JARS%;%C3P0_JARS%;%APPLET_JARS%;


%SAHI_HOME%\lib\ant-sahi.jar; should be added to classpath.

Email code now starts working but make sure you add username and password and port as integer.

function sendEmail($emailSubject, $emailBody) {
var $host = "mailhost.com";
var $port = 25;
var $username = "username";
var $password = "passwd";
//var $username = null; //fails
//var $password = null; // fails

var $isSSL = false; // set to true if you use SSL
var $mailer = new Packages.net.sf.sahi.ant.Mailer($host, $port, $username, $password, $isSSL);
$mailer.setFrom("SahiPro610@NoReply.example.com");
$mailer.setTo("to@example.com");
$mailer.addTo("to2@example.com");
$mailer.setSubject($emailSubject);
$mailer.setBody($emailBody);
$mailer.addAttachment("Attachment.zip", "d:/Attachment.zip");
$mailer.send();
}

function sendEmailWithProps($emailSubject, $emailBody) {
var $props = loadProperties(_resolvePath("email.properties"), false);
var $mailer = new Packages.net.sf.sahi.ant.Mailer($props);
$mailer.addTo("to1@example.com");
$mailer.addTo("to2@example.com");//This will append to the already present recipient address from properties file
$mailer.setBody($emailBody);
$mailer.setSubject($emailSubject);
$mailer.addAttachment("Attachment.zip", "d:/Attachment.zip");
$mailer.send();
}

function loadProperties($path, $isXML) {
var $props = new java.util.Properties();
try {
var $inStream = new java.io.FileInputStream($path);
if ($isXML) {
$props.loadFromXML($inStream);
} else {
$props.load($inStream);
}
$inStream.close();
} catch (e) {
// do nothing
}
return $props;
}



_log("This is email testing");
_debug("This is debug for email sending test");
sendEmail("Sahi Pro Email Subject", "Sahi Pro Email Body");
sendEmailWithProps("Sahi Pro Email Subject with Props ", "Sahi Pro Email Body - with Props");


If things dont work with props copy the email.properties file to scripts directory and check again.
Sign In or Register to comment.