Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7155
| From | Nigel Wade <nmw-news@ion.le.ac.uk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: JavaMail bug? |
| Date | 2011-08-17 10:29 +0100 |
| Message-ID | <9b1fvlFjn7U1@mid.individual.net> (permalink) |
| References | (6 earlier) <j1771e$smf$1@localhost.localdomain> <99qjntFk6uU1@mid.individual.net> <j19l2v$h45$1@localhost.localdomain> <99sfoiFs99U1@mid.individual.net> <j2em46$gkh$1@localhost.localdomain> |
On 16/08/11 22:06, Martin Gregorie wrote:
> On Wed, 03 Aug 2011 09:38:41 +0100, Nigel Wade wrote:
>
>> 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.
>>
> Final comment:
>
> On Sunday this whole mess niggled me again, so I ripped out the property
> setting the default MTAname and replaced the call of tr.send(msg) with
> tr.sendMessage(msg, recipients) so the Transport acquired from the
> Session is used. This all works as expected: there's only the one EHLO
> conversation and the recipient is validated (which I don't remember
> seeing earlier).
>
>
Yes, I think that's the best way to do authentication. If you look at
the top of the Javadocs for com.sun.mail.smtp (the protocol which is
actually used behind the scenes, it's not exactly obvious because the
design hides this from you) it states:
To use SMTP authentication you'll need to set the mail.smtp.auth
property (see below) or provide the SMTP Transport with a username and
password when connecting to the SMTP server. You can do this using one
of the following approaches:
* Provide an Authenticator object when creating your mail Session
and provide the username and password information during the
Authenticator callback.
Note that the mail.smtp.user property can be set to provide a
default username for the callback, but the password will still need to
be supplied explicitly.
This approach allows you to use the static Transport send method
to send messages.
* Call the Transport connect method explicitly with username and
password arguments.
This approach requires you to explicitly manage a Transport
object and use the Transport sendMessage method to send the message. The
transport.java demo program demonstrates how to manage a Transport
object. The following is roughly equivalent to the static Transport send
method, but supplies the needed username and password:
Transport tr = session.getTransport("smtp");
tr.connect(smtphost, username, password);
msg.saveChanges(); // don't forget this
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
--
Nigel Wade
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
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
csiph-web