From: nogales on
On 8 jun, 11:08, jesbox <jesb...(a)gmail.com> wrote:

>                 new Mailer(host, 25, username, password).sendMail(email);

> The stacktrace is then becomes :
> ERROR - Could not connect to SMTP host: localhost, port: 25
> javax.mail.MessagingException: Could not connect to SMTP host:
> localhost, port: 25;
>   nested exception is:
>         java.net.ConnectException: Connection refused
>         at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:
> 1545)
>         at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:
> 453)
>         at javax.mail.Service.connect(Service.java:313)
>         at javax.mail.Service.connect(Service.java:172)
>         at javax.mail.Service.connect(Service.java:121)
>         at javax.mail.Transport.send0(Transport.java:190)
>         at javax.mail.Transport.send(Transport.java:120)
>         at org.codemonkey.vesijama.Mailer.sendMail(Mailer.java:174)
>         at TestMail.sendMail(TestMail.java:56)
>         at TestMail.testMail(TestMail.java:47)
>         at TestMail.main(TestMail.java:33)
> Caused by: java.net.ConnectException: Connection refused
>         at java.net.PlainSocketImpl.socketConnect(Native Method)
>         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
>         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:
> 195)

It seems that the variable 'host' is an empty String.
From: Lew on
jesbox wrote:
>> new Mailer(host, 25, username, password).sendMail(email);

Dude, do not use TAB characters to indent Usenet posts.

Use a maximum of four spaces (that's space characters) per indent level.

>> The stacktrace is then becomes :
>> ERROR - Could not connect to SMTP host: localhost, port: 25
>> javax.mail.MessagingException: Could not connect to SMTP host:
>> localhost, port: 25;

nogales wrote:
> It seems that the variable 'host' is an empty String.

Is that why it's trying to mail via localhost?

Which'd be fine if localhost were running a mail service on port 25.

One wonders why in
> final String host = System.getProperty("smtp.gmail.com") !=
> null ?
>
> System.getProperty("smtp.gmail.com") : "";

the lack of the "smtp.gmail.com" property is not logged, nor even a logger
defined for the class, especially after all that superfluous effort to
initialize the root logger.

Don't allow preconditions (or other invariants) to fail silently.

--
Lew
From: Martin Gregorie on
On Tue, 08 Jun 2010 03:57:10 -0700, nogales wrote:

>
> It seems that the variable 'host' is an empty String.
>
Either that or there is no MTA listening on localhost:25


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
From: Nigel Wade on
On Tue, 08 Jun 2010 02:08:50 -0700, jesbox wrote:

> Dear all,
>
> I am trying to get JavaMail to work and have picked a library "Very
> Simple Java Mail" at http://code.google.com/p/vesijama/ that seems to
> provide a nice degree of abstraction. I would be grateful for advice on
> how to find out what goes wrong, e.g. why my program does not reach
> Internet. I run Java 1.6 on OSX 10.5.8 and Tomcat v6.0.
>


> The stacktrace is then becomes :
> ERROR - Could not connect to SMTP host: localhost, port: 25
> javax.mail.MessagingException: Could not connect to SMTP host:
> localhost, port: 25;
> nested exception is:
> java.net.ConnectException: Connection refused at
> com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:
> 1545)
> at com.sun.mail.smtp.SMTPTransport.protocolConnect
(SMTPTransport.java:

That results from attempting to connect to an SMTP service running on
your computer, and there is none running.

Presumably the lookup for smtp.gmail.com in System properties fails.
Hardly surprising really, why would it exist in the System properties? So
host is set to an empty string. Not knowing what the
org.codemonkey.vesijama.Mailer class does with the "host" argument if
it's empty, I am guessing that it attempts a connection to localhost.
Since you don't have a SMTP service running the connection fails with a
MessagingException and you get a stack trace.

I think you would have better success if you set the host, username and
password variables to the values you attempt to lookup in System
properties.

--
Nigel Wade

From: jesbox on
Thanks for the wakeup, now I'm heading for the next trouble.

It seems I need an https connection to get to gmail.