Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6478 > unrolled thread
| Started by | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| First post | 2011-07-23 20:32 +0000 |
| Last post | 2011-08-01 12:54 +0000 |
| Articles | 20 on this page of 31 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-23 20:32 +0000
Re: JavaMail bug? Knute Johnson <september@knutejohnson.com> - 2011-07-23 20:54 -0700
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-24 09:50 +0000
Re: JavaMail bug? Knute Johnson <september@knutejohnson.com> - 2011-07-24 09:27 -0700
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-25 19:36 +0000
Re: JavaMail bug? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2011-07-25 23:00 -0700
Re: JavaMail bug? Steve Sobol <sjsobol@JustThe.net> - 2011-07-25 23:18 -0700
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-26 17:49 +0000
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-26 17:42 +0000
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-07-25 15:40 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-25 19:54 +0000
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-25 20:11 +0000
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-29 21:32 +0000
Re: JavaMail bug? Knute Johnson <september@knutejohnson.com> - 2011-07-29 16:26 -0700
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-08-01 13:20 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-08-01 21:49 +0000
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-08-02 16:34 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-08-02 20:01 +0000
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-08-03 09:27 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-08-08 22:50 +0000
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-08-09 13:31 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-08-09 22:47 +0000
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-08-10 09:34 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-08-10 19:37 +0000
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-08-03 09:38 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-08-16 21:06 +0000
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-08-17 10:29 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-08-17 19:54 +0000
Re: JavaMail bug? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-08-18 09:34 +0100
Re: JavaMail bug? Martin Gregorie <martin@address-in-sig.invalid> - 2011-08-18 19:50 +0000
Re: JavaMail bug? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-01 12:54 +0000
Page 1 of 2 [1] 2 Next page →
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-07-23 20:32 +0000 |
| Subject | JavaMail bug? |
| Message-ID | <j0fb5e$sat$1@localhost.localdomain> |
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://kiwi@zoogz.gregorie.org",
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?
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
[toc] | [next] | [standalone]
| From | Knute Johnson <september@knutejohnson.com> |
|---|---|
| Date | 2011-07-23 20:54 -0700 |
| Message-ID | <j0g51p$7jg$1@dont-email.me> |
| In reply to | #6478 |
On 7/23/2011 1:32 PM, Martin Gregorie wrote:
> 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://kiwi@zoogz.gregorie.org",
> 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?
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-07-24 09:50 +0000 |
| Message-ID | <j0gpth$8ho$1@localhost.localdomain> |
| In reply to | #6497 |
On Sat, 23 Jul 2011 20:54:31 -0700, Knute Johnson wrote: > 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. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <september@knutejohnson.com> |
|---|---|
| Date | 2011-07-24 09:27 -0700 |
| Message-ID | <j0hh65$adu$1@dont-email.me> |
| In reply to | #6500 |
On 7/24/2011 2:50 AM, Martin Gregorie wrote: > On Sat, 23 Jul 2011 20:54:31 -0700, Knute Johnson wrote: > >> 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. 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. -- Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-07-25 19:36 +0000 |
| Message-ID | <j0kgkj$8bg$2@localhost.localdomain> |
| In reply to | #6509 |
On Sun, 24 Jul 2011 09:27:49 -0700, Knute Johnson wrote: > On 7/24/2011 2:50 AM, Martin Gregorie wrote: >> 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? > 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. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Date | 2011-07-25 23:00 -0700 |
| Message-ID | <YJsXp.28709$tp.6608@newsfe06.iad> |
| In reply to | #6549 |
On 7/25/2011 12:36 PM, Martin Gregorie wrote: > 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. -- Knute Johnson s/knute/nospam/
[toc] | [prev] | [next] | [standalone]
| From | Steve Sobol <sjsobol@JustThe.net> |
|---|---|
| Date | 2011-07-25 23:18 -0700 |
| Message-ID | <MPG.2897fbf89be8972c9897cb@news.justthe.net> |
| In reply to | #6563 |
In article <YJsXp.28709$tp.6608@newsfe06.iad>, Knute Johnson says... > > On 7/25/2011 12:36 PM, Martin Gregorie wrote: > > 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. Uh, what? I always thought Pearblossom was just a small patch of empty land :) -- Steve Sobol - Programming/WebDev/IT Support sjsobol@JustThe.net
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-07-26 17:49 +0000 |
| Message-ID | <j0munq$ss1$2@localhost.localdomain> |
| In reply to | #6564 |
On Mon, 25 Jul 2011 23:18:05 -0700, Steve Sobol wrote: > In article <YJsXp.28709$tp.6608@newsfe06.iad>, Knute Johnson says... >> >> On 7/25/2011 12:36 PM, Martin Gregorie wrote: >> > 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. > > 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. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-07-26 17:42 +0000 |
| Message-ID | <j0mu99$ss1$1@localhost.localdomain> |
| In reply to | #6563 |
On Mon, 25 Jul 2011 23:00:24 -0700, Knute Johnson wrote: > On 7/25/2011 12:36 PM, Martin Gregorie wrote: >> 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. Gotcha. Google Earth finds all. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Nigel Wade <nmw-news@ion.le.ac.uk> |
|---|---|
| Date | 2011-07-25 15:40 +0100 |
| Message-ID | <995djcFq0nU1@mid.individual.net> |
| In reply to | #6478 |
On 23/07/11 21:32, Martin Gregorie wrote:
> 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://kiwi@zoogz.gregorie.org",
> 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://user@mail.ion.le.ac.uk
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.
--
Nigel Wade
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-07-25 19:54 +0000 |
| Message-ID | <j0khlj$8bg$3@localhost.localdomain> |
| In reply to | #6534 |
On Mon, 25 Jul 2011 15:40:44 +0100, Nigel Wade wrote: > 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? -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-07-25 20:11 +0000 |
| Message-ID | <j0kilj$8bg$4@localhost.localdomain> |
| In reply to | #6551 |
On Mon, 25 Jul 2011 19:54:27 +0000, Martin Gregorie wrote: > On Mon, 25 Jul 2011 15:40:44 +0100, Nigel Wade wrote: > >> 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. > 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. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-07-29 21:32 +0000 |
| Message-ID | <j0v8t7$os9$1@localhost.localdomain> |
| In reply to | #6552 |
On Mon, 25 Jul 2011 20:11:31 +0000, Martin Gregorie wrote:
> 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 = "martin@gregorie.org";
String from = "ma@gregorie.org";
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.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <september@knutejohnson.com> |
|---|---|
| Date | 2011-07-29 16:26 -0700 |
| Message-ID | <j0vfi9$bmr$1@dont-email.me> |
| In reply to | #6668 |
On 7/29/2011 2:32 PM, Martin Gregorie wrote:
> On Mon, 25 Jul 2011 20:11:31 +0000, Martin Gregorie wrote:
>
>> 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 = "martin@gregorie.org";
> String from = "ma@gregorie.org";
> 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.
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Nigel Wade <nmw-news@ion.le.ac.uk> |
|---|---|
| Date | 2011-08-01 13:20 +0100 |
| Message-ID | <99njvpFv11U1@mid.individual.net> |
| In reply to | #6668 |
On 29/07/11 22:32, Martin Gregorie wrote: > 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)? -- Nigel Wade
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-08-01 21:49 +0000 |
| Message-ID | <j1771e$smf$1@localhost.localdomain> |
| In reply to | #6712 |
On Mon, 01 Aug 2011 13:20:09 +0100, Nigel Wade wrote: > 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. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Nigel Wade <nmw-news@ion.le.ac.uk> |
|---|---|
| Date | 2011-08-02 16:34 +0100 |
| Message-ID | <99qjntFk6uU1@mid.individual.net> |
| In reply to | #6716 |
On 01/08/11 22:49, Martin Gregorie wrote:
> On Mon, 01 Aug 2011 13:20:09 +0100, Nigel Wade wrote:
>
>> 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.
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.
--
Nigel Wade
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-08-02 20:01 +0000 |
| Message-ID | <j19l2v$h45$1@localhost.localdomain> |
| In reply to | #6750 |
On Tue, 02 Aug 2011 16:34:20 +0100, Nigel Wade wrote: >> 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. > 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://kiwi@zoogz.gregorie.org smtp://kiwi@zoogz.gregorie.org 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. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Nigel Wade <nmw-news@ion.le.ac.uk> |
|---|---|
| Date | 2011-08-03 09:27 +0100 |
| Message-ID | <99sf3vFncoU1@mid.individual.net> |
| In reply to | #6763 |
On 02/08/11 21:01, Martin Gregorie wrote: > On Tue, 02 Aug 2011 16:34:20 +0100, Nigel Wade wrote: > >>> 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. >> > 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'. 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://kiwi@zoogz.gregorie.org > smtp://kiwi@zoogz.gregorie.org > 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. > 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. > >
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2011-08-08 22:50 +0000 |
| Message-ID | <j1pp73$tje$1@localhost.localdomain> |
| In reply to | #6771 |
On Wed, 03 Aug 2011 09:27:43 +0100, Nigel Wade wrote: > Note that it does not include AUTH, so no authentication will be allowed > and the client should not attempt it. > Fair point. > This isn't a good idea. It's an open invitation to spammers to verify > the existence of every recipient in your domain. > Except that this server really is private: my firewall blocks all inbound connection requests and so its only contact with the outside world are its outbound SMTP connections to my ISP's mail server when it needs to send mail. Incoming mail is fetched by getmail and passed to the MTA via the Postfix.sendmail utility. > 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. > OK, that makes sense. Your point about Transport.send() being static would seem to explain the behaviour I'm seeing, but there's still a heap of anomalies, mainly in the documentation: - Transport.send() says that its not a good idea to inherit the connection from a Session and doesn't provide a suitable way of setting the hostname (at least its docs don't mention one or mention the use of properties, though obviously they are used by it. - now go and look at SMTPTransport. Its documentation includes example code doing as we did, and getting the connection from Session. Gaargh! The double connect is now explained by the Session.connect() making one connection and Transport.send() making a second -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.java.programmer
csiph-web