Email Examples

Contents Hide

  

Example 1. Create and send email

ScriptSession.logInfo("Sending email...") ;

 

var email = new Email("mail.domainname.com.au", 25, "dev@domainname.com.au", "test1@domainname.com.au") ;

email.setSubject("Testing") ;

email.setBody("Please ignore !\nThis is test message\n\nRegards\nBright Software") ;

//email.setText("Testing", "Testing ignore!") ;

email.addCC("test2@domainname.com.au") ;

email.addAttachment("\\temp\\Instructions.txt") ;

email.send() ;

 

ScriptSession.logInfo("Email sent successfully.") ;

Note:

Example 2. SMTP Authentication via TLS

ScriptSession.logInfo("Sending email...") ;

 

var email = new Email("smtp.gmail.com", 587, "example.src@gmail.com", "example.dest@gmail.com") ;

email.setSubject("Test Email via TLS") ;

email.setBody("Test Body") ;

email.setUserCredentials("example.src@gmail.com", "password");

email.setProperty("mail.smtp.starttls.enable", "true") ;

email.send() ;

 

ScriptSession.logInfo("Email sent successfully.") ;

Note:

Example 3. IMAP Authentication via SSL

ScriptSession.logInfo("Sending email...") ;

 

var email = new Email("imap.gmail.com", 993, "example.src@gmail.com", "example.dest@gmail.com") ;

email.setSubject("Test Email via SSL") ;

email.setBody("Test Body") ;

email.setUserCredentials("example.src@gmail.com", "password");

email.setEnableSSL(true);

email.setProtocol("imap");

email.send() ;

 

ScriptSession.logInfo("Email sent successfully.") ;

Note: