WSO2 BPS - mailing activity

2019-05-26 08:47发布

I need to have an activity that send a mail at a certain point of the BPEL process.

Is there a "mail activity" or do I have to code a sort of web services to invoke so that I call the service and let it send the mail?

Could it be a solution to use the ESB for this business?

How to connect the two (again with a web services or there is a quicker and easiest way to link them)?

Could it be a good solution in this case to add the ESB feature to BPS to add it the transport feature without having to add the ESB just for this?

Also I've seen that there are some example around that uses the transportSender in axis2.xml than using a proxy, but it seems that this method send the mail always to the same address I need to be able to send a mail to a subject (an possible cc and bcc) from parameters of the process (on a previous step I read data from DB and there is the address information) could the tensportSender be the path to follow or I have to develop the mailing service?

Any hint?

Thanks

Luca

标签: wso2 bpel
2条回答
你好瞎i
2楼-- · 2019-05-26 08:58

As mentioned before, currently there is no mailing activity built-in for WSO2 BPEL, but you can get this functionality by invoking an external web service(DSS, AS) from inside the BPEL workflow.

I've created one workflow with such functionality couple days ago. Basically I created and Axis2 service that is just Java code for sending email, in which I can provide the parameters such as subject, content and receiver, so once you invoke the service you can send the email to any email address. I deployed the Axis2 service mentioned into a WSO2 DSS and invoke it from BPEL workflow that later on I deployed into WSO2 BPS.

The Java code I used for sendin the email is the following:

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailSender {

    public static void main(String emailAddress, String content){

        String host = "smtp.gmail.com";
        String from = "example@gmail.com";
        String subject = "Subject example";



        Properties props = System.getProperties();
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.user", from);
        props.put("mail.smtp.password", "");
        props.put("mail.smtp.port", "587");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.auth", "true");

        try{
            Session session = Session.getDefaultInstance(props, null);
            InternetAddress to_address = new InternetAddress(emailAddress);

            MimeMessage message = new MimeMessage(session);         
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, to_address);
            message.setSubject(subject);        
            message.setContent(content, "text/html; charset=UTF-8");

            Transport transport = session.getTransport("smtp");
            transport.connect("smtp.gmail.com","example@gmail.com","Password");
            transport.sendMessage(message, message.getAllRecipients());
            transport.close();


            }

            catch (MessagingException mex) {
            System.out.println("send failed, exception: " + mex);
            }
    }
}
查看更多
Animai°情兽
3楼-- · 2019-05-26 09:04

Currently, there is no mailing activity in BPS as a built-in activity.

But Yes, you can achieve your task by combining ESB and BPS. You can do it as follows. First expose ESB email sending service as a proxy and then call that service using BPS. It is better to use a separate ESB for this task, since I have faced some difficulties when integrating ESB features into BPS.

查看更多
登录 后发表回答