Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6670

Re: JavaMail bug?

From Knute Johnson <september@knutejohnson.com>
Newsgroups comp.lang.java.programmer
Subject Re: JavaMail bug?
Date 2011-07-29 16:26 -0700
Organization A noiseless patient Spider
Message-ID <j0vfi9$bmr$1@dont-email.me> (permalink)
References <j0fb5e$sat$1@localhost.localdomain> <995djcFq0nU1@mid.individual.net> <j0khlj$8bg$3@localhost.localdomain> <j0kilj$8bg$4@localhost.localdomain> <j0v8t7$os9$1@localhost.localdomain>

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-01 12:54 +0000

csiph-web