AnsweredAssumed Answered

How to set mail.smtp.localhost?

Question asked by andregs on May 10, 2011
Latest reply on May 13, 2011 by andregs
Hi,

I've configured cfg.activiti\standalone\activiti.cfg.xml as follows:

 <property name="mailServerHost" value="my.smtp.com" />
<property name="mailServerPort" value="25" />
<property name="mailServerDefaultFrom" value="my@email.com" />
<property name="mailServerUsername" value="my@email.com" />
<property name="mailServerPassword" value="mypass" />

Then I use a MailTask to send an e-mail. But the process crashes with a “javax.mail.MessagingException: 501 5.5.4 Invalid Address”.

So, I tried this:

Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", SMTP_HOST_NAME);
props.setProperty("mail.smtp.auth", "true");
//props.setProperty("mail.smtp.localhost", "localhost");

Session mailSession = Session.getDefaultInstance(props, new Authenticator() {
   public PasswordAuthentication getPasswordAuthentication() {
      String username = SMTP_AUTH_USER;
      String password = SMTP_AUTH_PWD;
      return new PasswordAuthentication(username, password);
   }
});

mailSession.setDebug(true);
Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);
message.setContent("This is a test", "text/plain");
message.setFrom(new InternetAddress(SMTP_AUTH_USER));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(TO_ADDRESS));

transport.connect();
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();

That gave me the same exception. But by uncommenting the “mail.smtp.localhost” line, the e-mail is successfully sent.

So this is the question: how can I configure that property in activity.cfg.xml file? Maybe I have to replace MailTask by a regular ServiceTask and send e-mails by myself?

Thanks in advance,

Outcomes