WSO2 BPS - mailing activity

邮差的信 提交于 2019-12-07 21:09:51

问题


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


回答1:


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);
            }
    }
}



回答2:


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.



来源:https://stackoverflow.com/questions/16100884/wso2-bps-mailing-activity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!