cancel
Showing results for 
Search instead for 
Did you mean: 

Mail Task

amani
Champ in-the-making
Champ in-the-making
Hi, I have a problem with send Mail Task, I don't received anything. I use Apache James and JavaMail.
I put this code in listener of MailTask:
public class MailTaskNotification implements TaskListener{

private static final long serialVersionUID = 1L;

private static String HOST = "smtp.gmail.com";
private static String USER = "myAddress@gmail.com";
private static String PASSWORD = "******";
private static String PORT = "465";
private static String FROM = "myAddress@gmail.com";
private static String TO = "myAddress@gmail.com";

private static String STARTTLS = "true";
private static String AUTH = "true";
private static String DEBUG = "true";
private static String SOCKET_FACTORY = "javax.net.ssl.SSLSocketFactory";
private static String SUBJECT = "Testing JavaMail API";
private static String TEXT = "This is a test message from my java application. Just ignore it";

@Override
public void notify(DelegateTask task) {
System.out.println("Enter in Email Task");   
//Use Properties object to set environment properties
Properties props = new Properties();

props.put("mail.smtp.host", HOST);
props.put("mail.smtp.port", PORT);
props.put("mail.smtp.user", USER);

props.put("mail.smtp.auth", AUTH);
props.put("mail.smtp.starttls.enable", STARTTLS);
props.put("mail.smtp.debug", DEBUG);

props.put("mail.smtp.socketFactory.port", PORT);
props.put("mail.smtp.socketFactory.class", SOCKET_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");

try {

//Obtain the default mail session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);

//Construct the mail message
MimeMessage message = new MimeMessage(session);
message.setText(TEXT);
message.setSubject(SUBJECT);
message.setFrom(new InternetAddress(FROM));
message.addRecipient(RecipientType.TO, new InternetAddress(TO));
message.saveChanges();

//Use Transport to deliver the message
Transport transport = session.getTransport("smtp");
transport.connect(HOST, USER, PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
transport.close();

} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Mail sent successfully!");   
}
}
9 REPLIES 9

jbarrez
Star Contributor
Star Contributor
This doesn't sound like an Activiti problem … you are doing al the email sending yourself here…

amani
Champ in-the-making
Champ in-the-making
I want send a Mail Task. My Listener Task will be executed when Mail task was created. when i executed my project,  I can't find any exception in my console and I don't receive anything in my email box. I attached my bpm diagram.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Amani.

I did not find any error in your process definition.
Questions:
# Did you try to debug it?
# Do you have a jUnit test?

Regards
Martin

amani
Champ in-the-making
Champ in-the-making
1) Yes, I putted toggles when my process started but I didn't have any exceptions just this message appears in my console and I putted also toggle in My listener Task "MailTaskNotification" but it didn't enter:
****************** Start Approve Instruction ***********************
your process is started
>>>>>Sending data EHLO AZOUNA-PC<<<<<<
>>>>>Sending data MAIL FROM: <activiti@localhost><<<<<<
>>>>>Sending data RCPT TO: <azouna.amani@gmail.com><<<<<<
>>>>>Sending data DATA<<<<<<
>>>>>Sending data <<<<<<
>>>>>Sending data .<<<<<<
>>>>>Sending data QUIT<<<<<<

2) Yes, I tried to test with jUnit.

martin_grofcik
Confirmed Champ
Confirmed Champ
Isn't there any problem with wiser?


java.lang.NoSuchMethodError: org.apache.mina.transport.socket.nio.SocketAcceptor.<init>(ILjava/util/concurrent/ExecutorSmiley WinkV
at org.subethamail.smtp.server.SMTPServer.initService(SMTPServer.java:211)
at org.subethamail.smtp.server.SMTPServer.<init>(SMTPServer.java:147)
at org.subethamail.smtp.server.SMTPServer.<init>(SMTPServer.java:156)
at org.subethamail.wiser.Wiser.<init>(Wiser.java:61)

Regards
Martin

amani
Champ in-the-making
Champ in-the-making
Yes, when I tested with jUnit I have this problem with wiser. I added all library necessary but it stay this exception.

ekolesnikov
Champ in-the-making
Champ in-the-making
Hi Amani,

Based on our experience, sending emails directly from within the workflow (using Mail Task or bespoke TaskDelegate) seems to be a Very Bad Idea. For starters, you may not want the workflow to wait for the whole SMTP interaction (especially if there's a user waiting for the workflow to proceed), and what you definitely don't want is to the whole workflow to fail due to some silly SMTP error - not to mention MailTask's templating support being quite limited.
What we ended up doing was dumping all process variables to external service that would enqueue the email and return immediately. External task executor then would get the variables through the proper template engine (Velocity, Freemarker - or Jinja2 in our case since we have external web services built in Python and running on Google App Engine) and actually send the email through.

amani
Champ in-the-making
Champ in-the-making
OK, thank you.

jbarrez
Star Contributor
Star Contributor
@ekolesnikov: I would agree with that, specially in an enterprise setting that seems wise.