[ 
https://issues.apache.org/jira/browse/GERONIMO-6713?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Richard Zowalla closed GERONIMO-6713.
-------------------------------------
    Resolution: Fixed

Fixed on main in commit 3ac4d35, shipping in Mail_2.1_1.1.1 (1.1.0 was released 
while this was being worked on, so the fix missed it).

Transport.sendInternal grouped recipients in a Map keyed on the Transport 
returned by Session.getTransport(Address). That method builds a new instance on 
every call and Transport overrides neither equals nor hashCode, so every 
recipient ended up in its own group and the message was transmitted once per 
recipient, each carrying a single RCPT TO - exactly what this issue reports.

Recipients are now grouped by address type, which is what selects the protocol, 
and one Transport is created per group.

Verified against a recording SMTP server using the reproduction from the 
description: the DATA count goes from 2 to 1, with both RCPT TO commands inside 
the single transmission. Covered by the new 
SMTPTransportMultipleRecipientsTest. Jakarta Mail 2.1 TCK: 321/321.

> Mail with multiple recipients get sent multiple times
> -----------------------------------------------------
>
>                 Key: GERONIMO-6713
>                 URL: https://issues.apache.org/jira/browse/GERONIMO-6713
>             Project: Geronimo
>          Issue Type: Bug
>      Security Level: public(Regular issues) 
>          Components: mail, specs
>            Reporter: Alexander Falb
>            Priority: Major
>
> When sending a mail with javamail to multiple recipients, the mail is sent 
> multiple times with only one recipient each.
> h2. Steps to reproduce:
> Setup a project with following dependencies:
> {noformat}
> org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.7.1
> org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:1.8.4
> {noformat}
> Call JavaMail:
> {code:java}
> Properties props = new Properties();
> props.setProperty("mail.smtp.host", "localhost");
> props.setProperty("mail.smtp.port", "1025");
> Session session = Session.getInstance(props);
> MimeMessage message = new MimeMessage(session);
> message.setFrom(new InternetAddress("[email protected]"));
> message.setRecipients(Message.RecipientType.TO, new InternetAddress[] {new 
> InternetAddress("[email protected]"), new InternetAddress("[email protected]")});
> message.setSubject("Test Subject");
> message.setText("Some Mail Content");
> Transport.send(message);
> {code}
> h2. Actual Result (SMTP log):
> {noformat}
> SMTP connection from 127.0.0.1/127.0.0.1, new connection count: 1
> Server: 220 localhost.local ESMTP SubEthaSMTP null
> Client: EHLO localhost
> Server: 250-localhost.local
> 250-8BITMIME
> 250-AUTH LOGIN
> 250 Ok
> Client: MAIL FROM: <[email protected]>
> Server: 250 Ok
> Client: RCPT TO: <[email protected]>
> Server: 250 Ok
> Client: DATA
> Server: 354 End data with <CR><LF>.<CR><LF>
> Server: 250 Ok
> Client: QUIT
> Server: 221 Bye
> SMTP connection from 127.0.0.1/127.0.0.1, new connection count: 1
> Server: 220 localhost.local ESMTP SubEthaSMTP null
> Client: EHLO localhost
> Server: 250-localhost.local
> 250-8BITMIME
> 250-AUTH LOGIN
> 250 Ok
> Client: MAIL FROM: <[email protected]>
> Server: 250 Ok
> Client: RCPT TO: <[email protected]>
> Server: 250 Ok
> Client: DATA
> Server: 354 End data with <CR><LF>.<CR><LF>
> Server: 250 Ok
> Client: QUIT
> Server: 221 Bye
> {noformat}
> h2. Expected Result (SMTP log):
> {noformat}
> SMTP connection from 127.0.0.1/127.0.0.1, new connection count: 1
> Server: 220 localhost.local ESMTP SubEthaSMTP null
> Client: EHLO localhost.local
> Server: 250-localhost.local
> 250-8BITMIME
> 250-AUTH LOGIN
> 250 Ok
> Client: MAIL FROM:<[email protected]>
> Server: 250 Ok
> Client: RCPT TO:<[email protected]>
> Server: 250 Ok
> Client: RCPT TO:<[email protected]>
> Server: 250 Ok
> Client: DATA
> Server: 354 End data with <CR><LF>.<CR><LF>
> Server: 250 Ok
> Client: QUIT
> Server: 221 Bye
> {noformat}
> h2. Comments:
> I use [https://github.com/Nilhcem/FakeSMTP] to record the SMTP log. 
> Unfortunately the server strips the actual content of the message from the 
> log. It would be between each "Server: 354 End data with <CR><LF>.<CR><LF>" 
> and "Server: 250 Ok".
> The expected result is produced with {{javax:javaee-api:7.0}} instead of the 
> above mentioned {{org.apache.geronimo.*}} dependencies.
> I'm not 100% familiar with the allowed SMTP command sequences, but I would 
> suspect sending a message to 2 recipients should not result in sending the 
> entire message body twice over the wire with only one recipient each?
> I tracked the problem down to Transport#send(Message message, Address[] 
> addresses). This method groups recipients by Transport. The problem is 2 
> Transports are never the same, because Session#getTransport(..) uses 
> internally Session#getSerivce(Provider provder, URLName name) which in turn 
> instantiates a new Transport Object for each call. So the final 
> Transport-to-Address Map looks like this: \{SMTPTransport->[[email protected]], 
> SMTPTransport->[[email protected]]}
>  javax:javaee-api:7.0 works around this, by grouping by an 
> Transportidentifierstring "rfc822", which a map like this: \{"rfc822": 
> [[email protected], [email protected]]}
> I tried upgrading to the latest versions of {{org.apache.geronimo.*}} with no 
> success.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to