Java Mail code fails on deployment to Jelastic

660 views Asked by At

I have a Tomcat/Eclipse running a dynamic web project. This includes a known good .war as it's main codebase. The mail .jar is mail.1.4.5.jar.

When used locally, the setup, when configured accurately, delivers email via tests no problem. It can deliver to a variety of ports, and two very different SMTP servers. But when deployed to Jelastic, the app fails to deliver mail.

I could list the errors, they are several, including reports on transport issues. The key error, which may provide some answers, is that when Java Mail, on the Jelastic deployment, is configured to port 25, the mail is reported by the app as having been delivered. This works on both servers. But the mail never arrives. I've checked junk, too, to make sure the mail was not caught by anti-spam.

The problem seems to be quite narrow - only port 25 is working on the mail delivery, and Java Mail thinks it has succeeded. But there are many reasons why the mail may not have arrived, and I'm not sure where to start or, in some cases such as catching outbound mail, how to debug.

This question may be related to,

Grails mail delivery works fine locally

but if this is the same issue, then the problem is Java-wide, not limited to Grails.

2

There are 2 answers

1
Anton On

Have you tried to troubleshoot that issue by means of using any other external SMTP server apart from localhost:25? For example, gmail SMTP?

1
Rob Crowther On

The sub-structure of this problems is likely wider even than Java, it may apply to all Jelastic deployment. But I'll cover Java.

The first step should be to check the applications dependencies, as is well-explained in the post the OP linked to. The OP explains they had the application working on test/development, but I mention this again as a common source of Java deployment errors.

Next, Jelastic does not provide a Mail Transport Application (which Java Mail uses for delivery). So any MTA provided on a Jelastic host is provided by the underlying operating system. Of course, most servers would have such a provision, but it may vary depending on the host.

This makes sense to me, as a mail transport is a separate service. If Jelastic provided a mail transport, the expectation would be control as a separate/monitorable/chargable plugin. But the lack of such a plugin means apps sending mail are dependant on the host's underlying provision (...but see down a little). This lack of transport may be logical, however, it is contrary to common expectations of a shared server.

My next remarks apply to Layershift's implementation of Jelastic, but I expect other Jelastic host provision is much the same.

  • Do you have a trail account and IPv4?
    Layershift's MTA is not enabled unless you have a paid account and a static IP address. It's as simple as that.
  • Layershift's MTA configuration
    Only works on Port 25, and no SSL.

If the OP was using Layershift, or a Jelastic host with similar software stack, that is why only port 25 works. This lack of provision is why mails apparently successfully delivered were never forwarded to a server (the OP could not have known this).

I find the provision of only port 25 limiting. Some SMTP servers, as an anti-spam measure, open other ports. However, I went through this myself with Layershift's support, and it seems their provision is not limited, but simply sketchy. Onwards...

Layershift are explicit about not relying on the underlying transport (for tests only, then). They point out that the email source would be from their upstream public IP, which is not intended for mail, and so would not, for example, satisfy anti-spam checks. Their stance is that the sending of transactional email is better handled by one of the new external services such as,

Mailjet, Mandrill, Sendgrid

(sorry, I can't post these links)

Note that some of these services have no charge for low usage.

Again, this makes a great deal of sense as service provision, but is contrary to common expectation.

Finally, if you have very specialist needs, Jelastic have enabled some code to run your own email server. This seems contrary to the needs of the OP - too much trouble and maintenance, but if that is the aim,

Jelastic - run your own mail server

Hope that helps.