ARIS Community - We Love BPM

How to send email using ARIS Script?

Amol's picture
by Amol Patil in Professional ARIS posted on 2011-10-11

Hi everyone,

 

Is there any way by which we can send email through ARIS Script?

I can see "javax.mail" jar file ARIS lib files. Can we use the classes in that?

 

Thanks,

Amol Patil

15083 Views
0 Likes
6 Comments
There are no attachments
Jens Heylmann posted on 2011-10-13

Sure

/*************************************************************
 * Mail CLASS
 *
 * This class provides methods to send emails via javax.mail 
 *
 * @Version: 1.1.1
 *
 *************************************************************/
 /*
 * This class provides methods to send emails via javax.mail 
 *
 * @param server The SMTP server address as DNS or IP
 */
function Mail( server ) { 
    /**
    * SMTP server
    */
    var m_server = server;          
    /**
    * send a email with a attachment to a list of recipients
    *
    * @param sReply - a email address
    * @param arrRecepients - array of recipients 
    * @param sSubject - the email subject
    * @param sContent - the email body content
    * @param sAttachmentFileName - filename and path to the attachment
    *
    * @return void
    */
    this.send = function(sReply, arrRecepients, sSubject, sContent, sAttachmentFileName) {
        var i = 0;
        var props = new java.util.Properties();
        var instSession = Packages.javax.mail.Session.getInstance(props, null);
        var smtpTransport = instSession.getTransport("smtp");
        
        props.setProperty("mail.smtp.auth", "false");
            
    
        smtpTransport.connect(m_server, "", "");
    
        var adrReply = new Packages.javax.mail.internet.InternetAddress(sReply);
        
        // Receiver Address:    
        var arrAdrRecipients = new Array();
        for (i = 0; i < arrRecepients.length; i++) {
            arrAdrRecipients.push(new Packages.javax.mail.internet.InternetAddress(arrRecepients[i]));
        }
        
        // do not change
        var msg = new Packages.javax.mail.internet.MimeMessage(instSession);
        msg.setFrom(adrReply);
        
        // insert proper date
        msg.setSentDate(new Date());
        
        // do not change
        msg.setReplyTo(new Array(adrReply));
        msg.setRecipients(Packages.javax.mail.internet.MimeMessage.RecipientType.TO, arrAdrRecipients);
        
        // "Subject": Subject of the mail    
        msg.setSubject(sSubject, "UTF-8");
        
        messagePart = new Packages.javax.mail.internet.MimeBodyPart();
        messagePart.setText(sContent);
        multipart = new Packages.javax.mail.internet.MimeMultipart();
        multipart.addBodyPart(messagePart);
        
        if (!sAttachmentFileName.equals("")) {                
            attachmentPart = new Packages.javax.mail.internet.MimeBodyPart();
            var fds = new Packages.javax.activation.FileDataSource(sAttachmentFileName);    
            attachmentPart.setDataHandler(new Packages.javax.activation.DataHandler(fds));
            attachmentPart.setFileName(fds.getName());
            multipart.addBodyPart(attachmentPart);
        }      
            
        msg.setContent(multipart);
                
        // do not change
        smtpTransport.sendMessage(msg, arrAdrRecipients);
        smtpTransport.close();    
    } 
   
    
}

 

Francois Suter posted on 2017-03-18

Hello,

I want to use my Gmail SMTP to send my email, but I keep being block by some "Unable to convert connection to SSL" error. Here is the code I use, thanks to you and different website :

        var props = new java.util.Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");
        props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
        
        var instSession = Packages.javax.mail.Session.getDefaultInstance(props, null);
        var smtpTransport = instSession.getTransport("smtp");
     
        smtpTransport.connect(m_server, user, psw);

 

Amol Patil posted on 2011-10-13

Hello Jens,

This is gr8. It is working with some small tweak. I was doing the same, and was stuck in Authenticating through server. I was using Authenticator object. Using "smtpTransport.connect()" helped me a lot.

And then i set some more properties to use SSL

props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");

Thanks again for your valueable help.

Regards,

Amol Patil

 

Vladimir Bis posted on 2011-12-22

Hi all,

I got error "client does not have permissions to submit mail to this server".

What's wrong?

Amol Patil posted on 2011-12-22

Hi Vladimir,

You need to contact your network administrator for allowing your ARIS server machine to send emails through the SMTP server.

Generally SMTP servers are configured to allow some specific machines to send mails.

Thanks,

Amol Patil

Martin Miskovic posted on 2015-07-15

Hi everybody,

First of all, thank you for sharing. It is really useful for me.

But I can not figure out how to specify a path to the attachment?
I always get an "The system cannot find the path specified" error.

Thank you for any help.

Martin