cancel
Showing results for 
Search instead for 
Did you mean: 

How to set mail.smtp.localhost?

andregs
Champ in-the-making
Champ in-the-making
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,
5 REPLIES 5

andregs
Champ in-the-making
Champ in-the-making
Please let me know if you need more information regarding my question.

Thanks,

jbarrez
Star Contributor
Star Contributor
What exactly does that property do? I mean, is it just setting the smtp servet host to localhost?

andregs
Champ in-the-making
Champ in-the-making
mail.smtp.localhost: Local host name used in the SMTP HELO or EHLO command. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly.
Source: http://javamail.kenai.com/nonav/javadocs/com/sun/mail/smtp/package-summary.html

When I don't set mail.smtp.localhost, javamail tries "EHLO André-PC" and "HELO André-PC", and they both fail. By properly setting the property, the "EHLO localhost" is used, and the mail is sent. Look:

DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "XXX.com.br", port 25, isSSL false
220 XXX.com.br Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at  Thu, 12 May 2011 08:45:15 -0300
DEBUG SMTP: connected to host "XXX.com.br", port: 25

EHLO André-PC
501 5.5.4 Invalid Address
HELO André-PC
501 5.5.4 Invalid Address
Exception in thread "main" javax.mail.MessagingException: 501 5.5.4 Invalid Address
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:2023)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:1440)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:644)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at br.com.test.MailTest.main(MailTest.java:40)
Thank you for your time,

jbarrez
Star Contributor
Star Contributor
Strange - never saw that happening (could it be something with your host configuration of your machine).

But to come back your question: the quickest solution for you will be to extends the existing MailActivityBehavior or create your own JavaDelegate.
The chance that this gets prioritized quickly in small.

andregs
Champ in-the-making
Champ in-the-making
Thanks for your tips. I think a dns / mail server config would also fix the issue.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.