Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: JavaMail bug? Date: Wed, 17 Aug 2011 19:54:15 +0000 (UTC) Organization: UK Free Software Network Lines: 53 Message-ID: References: <995djcFq0nU1@mid.individual.net> <99njvpFv11U1@mid.individual.net> <99qjntFk6uU1@mid.individual.net> <99sfoiFs99U1@mid.individual.net> <9b1fvlFjn7U1@mid.individual.net> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1313610855 8759 84.45.235.129 (17 Aug 2011 19:54:15 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Wed, 17 Aug 2011 19:54:15 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7166 On Wed, 17 Aug 2011 10:29:24 +0100, Nigel Wade wrote: > 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: > Yes, I found that too. > Transport tr = session.getTransport("smtp"); > tr.connect(smtphost, username, password); msg.saveChanges(); > // don't forget this tr.sendMessage(msg, > msg.getAllRecipients()); > tr.close(); > I'm not calling Message.saveChanges(), but as something wrapped your text up in a bit of a ball I'm not sure that your 'don't forget' refers to. Instead I hung onto the recipient array and just passed it into Transport.sendMessage(). It also works correctly. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |