execution.setVariable('toAddress', "myEmail@google.com");
execution.setVariable('subject', "groovy script sent this");
execution.setVariable('message', "test groovy mail");
SequenceFlow_161cak7
println "--------------- Email to: " + toAddress + " subject: ${subject} sent";
SequenceFlow_0hcf5jy
SequenceFlow_161cak7
SequenceFlow_0hcf5jy
import javax.mail.internet.*;
import javax.mail.*
import javax.activation.*
//def message = "test groovy mail";
//def subject = "2 groovy sent this";
//def toAddress = "volodymyr_m.kanivets@pivdenny.ua";
def fromAddress = "Test_BPM_Dev@pivdenny.ua";
def host = "mail.pivdenny.ua";
def port = "25";
Properties mprops = new Properties();
mprops.setProperty("mail.transport.protocol","smtp");
mprops.setProperty("mail.host",host);
mprops.setProperty("mail.smtp.port",port);
Session lSession = Session.getDefaultInstance(mprops,null);
MimeMessage msg = new MimeMessage(lSession);
//tokenize out the recipients in case they came in as a list
StringTokenizer tok = new StringTokenizer(toAddress,";");
ArrayList emailTos = new ArrayList();
while(tok.hasMoreElements()){
emailTos.add(new InternetAddress(tok.nextElement().toString()));
}
InternetAddress[] to = new InternetAddress[emailTos.size()];
to = (InternetAddress[]) emailTos.toArray(to);
msg.setRecipients(MimeMessage.RecipientType.TO,to);
InternetAddress fromAddr = new InternetAddress(fromAddress);
msg.setFrom(fromAddr);
msg.setFrom(new InternetAddress(fromAddress));
msg.setSubject(subject);
msg.setText(message);
Transport transporter = lSession.getTransport("smtp");
transporter.connect();
transporter.send(msg);