AnsweredAssumed Answered

Mail Task

Question asked by amani on Apr 1, 2014
Latest reply on Apr 22, 2014 by jbarrez
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!");   
}
}

Outcomes