JavaMail bug?

M

Martin Gregorie

I seem to have found a JavaMail-1.4.4 bug

If I try to open an SMTP connection by obtaining a transport instance
and then calling connect():

Transport tr = sesh.getTransport("smtp");
tr.connect(host, user, password);

where:
sesh is the current mail session,
host is "zoogz.gregorie.org"
user is "kiwi"
and password is a valid password for the user

Transport.connect() sets up the URLName "smtp://[email protected]",
which is what I expect, but then promptly fails with:

javax.mail.MessagingException:
Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused

when the local Postfix MTA on the machine I'm connecting from
(zappa.gregorie.org) is stopped.

If I restart the local Postfix instance the connect request succeeds and
the mail message is sent, but its headers clearly show that JavaMail
delivered it to the local MTA, which then passed it to the Postfix MTA on
zoogz.gregorie.org, which has been listening on port 25 the whole time.

IOW the Transport.connect(host,user,password) method sets up its target
URL as expected but then promptly ignores it and defaults to connecting
to localhost on port 25.

Have any of you seen this problem?
Have I done anything stupid?
Is there a workround?
 
K

Knute Johnson

I seem to have found a JavaMail-1.4.4 bug

If I try to open an SMTP connection by obtaining a transport instance
and then calling connect():

Transport tr = sesh.getTransport("smtp");
tr.connect(host, user, password);

where:
sesh is the current mail session,
host is "zoogz.gregorie.org"
user is "kiwi"
and password is a valid password for the user

Transport.connect() sets up the URLName "smtp://[email protected]",
which is what I expect, but then promptly fails with:

javax.mail.MessagingException:
Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused

when the local Postfix MTA on the machine I'm connecting from
(zappa.gregorie.org) is stopped.

If I restart the local Postfix instance the connect request succeeds and
the mail message is sent, but its headers clearly show that JavaMail
delivered it to the local MTA, which then passed it to the Postfix MTA on
zoogz.gregorie.org, which has been listening on port 25 the whole time.

IOW the Transport.connect(host,user,password) method sets up its target
URL as expected but then promptly ignores it and defaults to connecting
to localhost on port 25.

Have any of you seen this problem?
Have I done anything stupid?
Is there a workround?

The last time I used JavaMail I set it up differently with properties
and MimeMessages so I didn't use quite the same method as you did to
send. That's one of the problems with JM, you can get at the problem
from about 50 different ways. If you want to write a little simple test
program, I'll try it here. I've got mail servers I can test it on
although I don't have the host names with quite the same organization.

There wouldn't be MX records on the DNS for zoogz would there?
 
M

Martin Gregorie

The last time I used JavaMail I set it up differently with properties
and MimeMessages so I didn't use quite the same method as you did to
send. That's one of the problems with JM, you can get at the problem
from about 50 different ways. If you want to write a little simple test
program, I'll try it here. I've got mail servers I can test it on
although I don't have the host names with quite the same organization.
Thanks. I'll put together a suitably parameterised test program over the
next day few days (it looks like soarable weather in the first half of
the week - something that's been all too rare recently to miss for
anything).
There wouldn't be MX records on the DNS for zoogz would there?
Yes - I run a local DNS to handle names within my LAN and there is an MX
record for zoogz.
 
K

Knute Johnson

Thanks. I'll put together a suitably parameterised test program over the
next day few days (it looks like soarable weather in the first half of
the week - something that's been all too rare recently to miss for
anything).

Yes - I run a local DNS to handle names within my LAN and there is an MX
record for zoogz.

And it's pointing in the right place?

I just found out yesterday that my old friend Ron Gregg is running the
soaring operation at Crystallaire again. I towed gliders and flight
instructed for him in the late 70s. I've got to go out there and see
him and do some soaring this summer. I'm off to Las Vegas today to
install some software but maybe next week.
 
N

Nigel Wade

I seem to have found a JavaMail-1.4.4 bug

If I try to open an SMTP connection by obtaining a transport instance
and then calling connect():

Transport tr = sesh.getTransport("smtp");
tr.connect(host, user, password);

where:
sesh is the current mail session,
host is "zoogz.gregorie.org"
user is "kiwi"
and password is a valid password for the user

Transport.connect() sets up the URLName "smtp://[email protected]",
which is what I expect, but then promptly fails with:

javax.mail.MessagingException:
Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused

when the local Postfix MTA on the machine I'm connecting from
(zappa.gregorie.org) is stopped.

If I restart the local Postfix instance the connect request succeeds and
the mail message is sent, but its headers clearly show that JavaMail
delivered it to the local MTA, which then passed it to the Postfix MTA on
zoogz.gregorie.org, which has been listening on port 25 the whole time.

IOW the Transport.connect(host,user,password) method sets up its target
URL as expected but then promptly ignores it and defaults to connecting
to localhost on port 25.

That certainly seems to be the problem. The MessagingException shows
it's failing to connect to localhost.
Have any of you seen this problem?

No, mine works as expected. At least, when I attempt a simple
Transport.connect(host, user, pwd) it connects to my SMTP server on port
25. It doesn't authenticate because my SMTP server doesn't offer AUTH on
port 25. But it does connect to the correct host.
Have I done anything stupid?

Hard to say with the limited code you've provided.

This is the code I'm testing with.

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class TestMail {

static String SMTP_SERVER = "yahoo.com";

public static void main(String[] args) {

// Get system properties
Properties props = System.getProperties();

// Setup mail server
props.put("mail.smtp.host", SMTP_SERVER);

// Get session
Session session = Session.getDefaultInstance(props, null);

try {
Transport tr = session.getTransport("smtp");
tr.connect("mail.ion.le.ac.uk", "user", "password");
System.out.println(tr);
System.out.println(tr.getURLName());
}
catch(MessagingException e) {
e.printStackTrace();
}

}
}

The value of the parameter host to connect() is overriding that set in
the Properties, which the correct behaviour. The URL output is:
smtp://[email protected]

I see the connection on mail.ion.le.ac.uk, and the SMTP handshake, using
Wireshark.

My guess is that there's a mistake somewhere in the code you haven't
shown us yet.

BTW, what version of JavaMail are you using? I've tested the above code
with both 1.3.1 and 1.4.4.
 
M

Martin Gregorie

On 7/24/2011 2:50 AM, Martin Gregorie wrote:

And it's pointing in the right place?
Yes. I use Evolution on 'zappa' for general mail access. It is configured
to send mail to zoogz via SMTP and to get incoming mail from 'zoogz' via
a Dovecot POP3 server. This works regardless of whether the 'zappa' MTA
is running or not and, unlike the messages sent via JavaMail, *doesnt*
have a Received: header for 'zappa'.
I just found out yesterday that my old friend Ron Gregg is running the
soaring operation at Crystallaire again. I towed gliders and flight
instructed for him in the late 70s. I've got to go out there and see
him and do some soaring this summer.
Where does Crystallaire fly out of? Its not a name I know.
 
M

Martin Gregorie

This is the code I'm testing with.
Thanks (test code snipped).

I'll compile and run that as well as extracting an SSCE from my own code.
My guess is that there's a mistake somewhere in the code you haven't
shown us yet.
Possibly. On a quick look everything within the try/catch bolck looks
like what I'm going but I'm less certain that there are no differences in
the preceeding code that's getting hold of the Session.
BTW, what version of JavaMail are you using? I've tested the above code
with both 1.3.1 and 1.4.4.
I first noticed it with JavaMail 1.4.3. Since I noticed the problem I've
installed 1.4.4 and *think* I've been running against it. I said 'think'
because the JavaMail jar is called mail.jar in both versions and, as I
didn't reboot the machine or logout between nominal 1.4.3 and 1.4.4 tests
I'm not 100% sure that the later jar file got loaded.

Is there anything I can do to check which jar file is loaded, i.e. are
there any distinguishing marks inside the jar file that would tell me
which is loaded?
 
M

Martin Gregorie

Thanks (test code snipped).

I'll compile and run that as well as extracting an SSCE from my own
code.
I meant to add that I'm sorting out a bit of C at present. Running your
test program and extracting my SSCE it on the list behind it.
 
K

Knute Johnson

Where does Crystallaire fly out of? Its not a name I know.

Crystallaire is in Pearblossom, just a few miles southeast of Palmdale.
I met my wife there in 1976, she was one of my students.
 
M

Martin Gregorie

Crystallaire is in Pearblossom, just a few miles southeast of Palmdale.
I met my wife there in 1976, she was one of my students.

Gotcha. Google Earth finds all.
 
M

Martin Gregorie

Uh, what? I always thought Pearblossom was just a small patch of empty
land :)
The airfield is called Crystal, a few miles east of Pearblossom on the
far side of the river - follow the Pearblossom Highway until it crosses
the river and take the first turn south on 165 East. There's a trailer
park right next to it that makes Pearblossom look like paradise.
 
M

Martin Gregorie

I meant to add that I'm sorting out a bit of C at present. Running your
test program and extracting my SSCE it on the list behind it.
Sorted. Now back the the JavaMail problem:

I modified the TestMail SSCE to suit my environment by changing the
'mail.smtp.host' property to "ukfsn.org" (my ISP) and the transport
connect statement became

tr.connect("zoogz.gregorie.org", "kiwi", "n/a")

This works regardless of whether the local MTA is running or stopped.

Then I made my own SSCE, MATestMail, from code in my mail dispatch class.
The only differences between my SSCE and TestMail are that it does not
add the 'mail.smtp.host' property to system props and it gets the session
with "Session.getInstance(props)" rather than "Session.getDefaultInstance
(props, null)".

It also creates and sends a message to myself so the headers can be seen
and I added a quick and dirty hack to optionally turn on SMTP debugging.
Both turned out to be useful for working out exactly what was going on.

The 'gotcha' turned out to be my omission to set the 'mail.smtp.host'
property. I didn't do that because the connect() documentation says that
it overrides the default host. This turns out to be incorrect: the MTA
host named in connect() appears in all the debugging and is used by the
getURL method, *but* the hostname supplied in the 'mail.smtp.host'
property is what defines the MTA that is actually used. If the property
is omitted the MTA host name defaults to localhost.

When I added that property and messed about with its value I found the
following behaviour, which was clearly shown by looking at the test
message headers and the /var/log/maillog on zoogz:

- With the 'mail.smtp.host' property unset the local MTA is always used:
if its running the message is sent via 'localhost' and if it is stopped
JavaMail reports a connection failure.

- With it set to 'mail.ukfsn.org' the mail went via my ISP's mail server.

- With it set to 'zoogz.gregorie.org' the mail is sent directly to zoogz.

During all three property values the connect() method was using
"zoogz.gregorie.org" as the 'host' parameter.

For completeness, here's my SSCE:

import java.util.Date;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class MATestMail
{
public static void main(String args[])
{
String host = "zoogz.gregorie.org";
String user = "kiwi";
String password = "n/a";
String to = "(e-mail address removed)";
String from = "(e-mail address removed)";
String subject = "Test message";
boolean debug = true;
Session sesh;

try
{
Properties props = System.getProperties();

sesh = Session.getInstance(props);
if (args.length > 0)
sesh.setDebug(debug);

MimeMessage msg = new MimeMessage(sesh);
MimeMultipart body = new MimeMultipart();
InternetAddress[] recipients = {new InternetAddress(to)};
InternetAddress sender = new InternetAddress(from);
msg.setFrom(sender);
msg.setRecipients(Message.RecipientType.TO, recipients);
msg.setSubject(subject);
msg.setSentDate(new Date());
MimeBodyPart b = new MimeBodyPart();
b.setText("This is an SSCE test message\n");
body.addBodyPart(b);
msg.setContent(body);
msg.saveChanges();

Transport tr = sesh.getTransport("smtp");
tr.connect(host, user, password);
System.out.println(tr);
System.out.println(tr.getURLName());
tr.send(msg);
tr.close();
}
catch(MessagingException e)
{
e.printStackTrace();
}
}
}

This SSCE doesn't set 'mail.smtp.host' and so will fail if the localhost
MTA isn't running: I develop on a Linux box, so there's always a local
MTA - hence the comment about the localhost MTA not running rather than
it not existing.

To make this SSCE connect directly to the target MTA (zoogz) I added the
statement:

props.put("mail.smtp.host", "zoogz.gregorie.org");

immediately after the 'Properties props = System.getProperties();'
statement.

The description of Transport.connect(host, user, password) is not at all
clearly written, but having read it and the description of
Transport.connect(user, password) I still think it means that the values
supplied as connect() parameters should take precedence over those set
via the property system, however connect() is plainly written to do the
opposite, leaving me to wonder why connect(host, user, password) even
exists.

So, what do you think: have I found a bug?

Many thanks to Nigel and Knute for helpful suggestions and example code.
 
K

Knute Johnson

I meant to add that I'm sorting out a bit of C at present. Running your
test program and extracting my SSCE it on the list behind it.
Sorted. Now back the the JavaMail problem:

I modified the TestMail SSCE to suit my environment by changing the
'mail.smtp.host' property to "ukfsn.org" (my ISP) and the transport
connect statement became

tr.connect("zoogz.gregorie.org", "kiwi", "n/a")

This works regardless of whether the local MTA is running or stopped.

Then I made my own SSCE, MATestMail, from code in my mail dispatch class.
The only differences between my SSCE and TestMail are that it does not
add the 'mail.smtp.host' property to system props and it gets the session
with "Session.getInstance(props)" rather than "Session.getDefaultInstance
(props, null)".

It also creates and sends a message to myself so the headers can be seen
and I added a quick and dirty hack to optionally turn on SMTP debugging.
Both turned out to be useful for working out exactly what was going on.

The 'gotcha' turned out to be my omission to set the 'mail.smtp.host'
property. I didn't do that because the connect() documentation says that
it overrides the default host. This turns out to be incorrect: the MTA
host named in connect() appears in all the debugging and is used by the
getURL method, *but* the hostname supplied in the 'mail.smtp.host'
property is what defines the MTA that is actually used. If the property
is omitted the MTA host name defaults to localhost.

When I added that property and messed about with its value I found the
following behaviour, which was clearly shown by looking at the test
message headers and the /var/log/maillog on zoogz:

- With the 'mail.smtp.host' property unset the local MTA is always used:
if its running the message is sent via 'localhost' and if it is stopped
JavaMail reports a connection failure.

- With it set to 'mail.ukfsn.org' the mail went via my ISP's mail server.

- With it set to 'zoogz.gregorie.org' the mail is sent directly to zoogz.

During all three property values the connect() method was using
"zoogz.gregorie.org" as the 'host' parameter.

For completeness, here's my SSCE:

import java.util.Date;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class MATestMail
{
public static void main(String args[])
{
String host = "zoogz.gregorie.org";
String user = "kiwi";
String password = "n/a";
String to = "(e-mail address removed)";
String from = "(e-mail address removed)";
String subject = "Test message";
boolean debug = true;
Session sesh;

try
{
Properties props = System.getProperties();

sesh = Session.getInstance(props);
if (args.length> 0)
sesh.setDebug(debug);

MimeMessage msg = new MimeMessage(sesh);
MimeMultipart body = new MimeMultipart();
InternetAddress[] recipients = {new InternetAddress(to)};
InternetAddress sender = new InternetAddress(from);
msg.setFrom(sender);
msg.setRecipients(Message.RecipientType.TO, recipients);
msg.setSubject(subject);
msg.setSentDate(new Date());
MimeBodyPart b = new MimeBodyPart();
b.setText("This is an SSCE test message\n");
body.addBodyPart(b);
msg.setContent(body);
msg.saveChanges();

Transport tr = sesh.getTransport("smtp");
tr.connect(host, user, password);
System.out.println(tr);
System.out.println(tr.getURLName());
tr.send(msg);
tr.close();
}
catch(MessagingException e)
{
e.printStackTrace();
}
}
}

This SSCE doesn't set 'mail.smtp.host' and so will fail if the localhost
MTA isn't running: I develop on a Linux box, so there's always a local
MTA - hence the comment about the localhost MTA not running rather than
it not existing.

To make this SSCE connect directly to the target MTA (zoogz) I added the
statement:

props.put("mail.smtp.host", "zoogz.gregorie.org");

immediately after the 'Properties props = System.getProperties();'
statement.

The description of Transport.connect(host, user, password) is not at all
clearly written, but having read it and the description of
Transport.connect(user, password) I still think it means that the values
supplied as connect() parameters should take precedence over those set
via the property system, however connect() is plainly written to do the
opposite, leaving me to wonder why connect(host, user, password) even
exists.

So, what do you think: have I found a bug?

Many thanks to Nigel and Knute for helpful suggestions and example code.

Looks like a bug to me. I tried to search the Sun bug list but it isn't
working today. I also looked around the Internet but didn't see
anything there either. I'd try to file a bug report.
 
N

Nigel Wade

The 'gotcha' turned out to be my omission to set the 'mail.smtp.host'
property. I didn't do that because the connect() documentation says that
it overrides the default host. This turns out to be incorrect: the MTA
host named in connect() appears in all the debugging and is used by the
getURL method,*but* the hostname supplied in the 'mail.smtp.host'
property is what defines the MTA that is actually used. If the property
is omitted the MTA host name defaults to localhost.

That is in conflict with my findings.

If you look at the message I posted, with the code I sent, you'll see
that I set mail.smtp.host to yahoo.com. However, in Transport.connect()
I explicitly connect to our mail server, overriding the value in the
mail.smtp.host property. This worked for me, as I mentioned in the post.
If I comment out that line, so mail.smtp.host is unset, it still
connects to our mail server as per the Transport.connect() host setting.

What does my code do if you run it exactly as is? Does it attempt to
connect to yahoo.com or our mail server (you won't actually be able to
connect, it's blocked on port 25)?
 
A

Andreas Leitgeb

Martin Gregorie said:
The 'gotcha' turned out to be my omission to set the 'mail.smtp.host'
property. I didn't do that because the connect() documentation says that
it overrides the default host. This turns out to be incorrect: the MTA
host named in connect() appears in all the debugging and is used by the
getURL method, *but* the hostname supplied in the 'mail.smtp.host'
property is what defines the MTA that is actually used. If the property
is omitted the MTA host name defaults to localhost.

Fwiw: I recently saw this kind of behaviour on Oracle on a Solaris host:
Some mailhost is configured for "smtp_out_server", which is supposed to
be used for utl_mail (pl/sql), but is also used for utl_smtp (ignoring
the hostname passed to utl_smtp.Open_Connection(...).)

I haven't used JavaMail myself, so can't say much about that.
 
M

Martin Gregorie

What does my code do if you run it exactly as is? Does it attempt to
connect to yahoo.com or our mail server (you won't actually be able to
connect, it's blocked on port 25)?
It fails connecting to your server.

So, where does THAT leave us? The only difference is that you call
getDefaultInstance(props) while I call getInstance(props) and, according
to the documentation, these should do exactly the same the first time
they're called.

BTW, I added the single property setting line to my application code so
that it uses the same hostname for 'mail.smtp.host' as connect(host,
user, passwd) does. That code now connects directly to the expected
server.

What does my SSCE do in your environment?

Do please post a response, but be aware that I'm unlikely to read it
until next week.
 
N

Nigel Wade

It fails connecting to your server.

Yes, well, that's what I said would happen.
So, where does THAT leave us?

With the fact that it /attempted/ to connect to our mail server - not
localhost, and not yahoo.com.
The only difference is that you call
getDefaultInstance(props) while I call getInstance(props) and, according
to the documentation, these should do exactly the same the first time
they're called.

I see the same behaviour with either getDefaultInstance() or
getInstance() - it connects to our mail server.
BTW, I added the single property setting line to my application code so
that it uses the same hostname for 'mail.smtp.host' as connect(host,
user, passwd) does. That code now connects directly to the expected
server.

What does my SSCE do in your environment?

I get:

javax.mail.MessagingException: Unknown SMTP host: zoogz.gregorie.org;
nested exception is:
java.net.UnknownHostException: zoogz.gregorie.org

I presume your DNS does not propagate upward from your zone. But it /is/
attempting to resolve that hostname via our DNS servers. It's not using
localhost.
 
M

Martin Gregorie

I get:

javax.mail.MessagingException: Unknown SMTP host: zoogz.gregorie.org;
nested exception is:
java.net.UnknownHostException: zoogz.gregorie.org

I presume your DNS does not propagate upward from your zone.
Correct. Its definitive only within my LAN and my firewall refused all
connections from outside.
But it /is/ attempting to resolve that hostname via our DNS servers.
It's not using localhost.
Interesting. I wonder why we're seeing a difference.
I assume you ran it with no command line arguments except (possibly)
'debug'.

When I do that the debugging text says that it was trying to connect to
zoogz.gregorie.org. Lines 7 and 8 show the first 220 followed a DEBUG
line reporting this. Then lines 31 and 32 report a failure to connect to
localhost and the resulting exception. If you're following this with
Wireshark I'd expect you to see the first connect attempt but maybe not
the second. Here's the debugging output:

$ java MATestMail debug
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 false
DEBUG SMTP: trying to connect to host "zoogz.gregorie.org", port 25, isSSL
false
220 zoogz.gregorie.org ESMTP Postfix
DEBUG SMTP: connected to host "zoogz.gregorie.org", port: 25

EHLO zappa.gregorie.org
250-zoogz.gregorie.org
250-PIPELINING
250-SIZE 51200000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "51200000"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
smtp://[email protected]
smtp://[email protected]
DEBUG: getProvider() returning javax.mail.Provider
[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
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:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect
(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at MATestMail.main(MATestMail.java:59)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress
(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at com.sun.mail.util.SocketFetcher.createSocket
(SocketFetcher.java:288)
at com.sun.mail.util.SocketFetcher.getSocket
(SocketFetcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer
(SMTPTransport.java:1900)
... 7 more

At this point I really am going to drop off the net for a few days - got
a 5AM start tomorrow.
 
N

Nigel Wade

Correct. Its definitive only within my LAN and my firewall refused all
connections from outside.

Interesting. I wonder why we're seeing a difference.
I assume you ran it with no command line arguments except (possibly)
'debug'.

I doubt it would help. Since the host doesn't resolve, there's really
nothing to debug. It can't connect to anything because it has no IP for
the connect.
When I do that the debugging text says that it was trying to connect to
zoogz.gregorie.org. Lines 7 and 8 show the first 220 followed a DEBUG
line reporting this. Then lines 31 and 32 report a failure to connect to
localhost and the resulting exception. If you're following this with
Wireshark I'd expect you to see the first connect attempt but maybe not
the second. Here's the debugging output:

$ java MATestMail debug
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 false
DEBUG SMTP: trying to connect to host "zoogz.gregorie.org", port 25, isSSL
false
220 zoogz.gregorie.org ESMTP Postfix
DEBUG SMTP: connected to host "zoogz.gregorie.org", port: 25

Here, you have connected to your mail server zoogz.gregorie.org
EHLO zappa.gregorie.org
250-zoogz.gregorie.org
250-PIPELINING
250-SIZE 51200000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

and received the standard mail server 250 connection response.

Note that it does not include AUTH, so no authentication will be allowed
and the client should not attempt it.
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "51200000"
DEBUG SMTP: Found extension "VRFY", arg ""

This isn't a good idea. It's an open invitation to spammers to verify
the existence of every recipient in your domain.
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
smtp://[email protected]
smtp://[email protected]
DEBUG: getProvider() returning javax.mail.Provider
[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false

I presume that this is due to the fact that the connect() above failed.
You have specified authentication by using a user/password, but the
connection does not allow authentication. When you subsequently use
tr.send() there is no open session so a default session is created which
appears to be to localhost.
 
N

Nigel Wade

I've just been reviewing the JavaMail API as it's a while since I used
it. You need to be aware that Transport.send() is a /static/ method. I
presume this means it takes no note of any connection established by an
object of class Transport, since the class method has no knowledge of
any contents of any Transport object. That probably explains why it uses
the values in the Session, not those established by the Transport object
you've created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top