Sending and seeing multiple recipients
I've been searching the forum and looking at old posts about using JavaMail to send to multiple recipients. I can send to multiple recipients ok, but my problem is I want to see all the recipients on the To line of the email. I tried a few different ways of setting the recipients but they all give me the same thing.
Right now I'm setting the recipients like this:
String recipient_list ="addr1@domain.com,addr2.domain2.com"
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(recipient_list,false));
Transport.send(msg);
The problem I have is that the messages get delivered to each recipient, but they are the only ones in the To field. The other address(es) do not show up.
In the debug of the smtp connection it only shows me the last address in the list:
DEBUG SMTP SENT: RCPT TO:<addr2.domain2.com>
DEBUG SMTP RCVD: 250 2.1.5 <addr2.domain2.com>... Recipient ok
Verified Addresses
addr2.domain2.com
How do you get all the recipients to show up in the To field on the resulting email?
Any help is appreciated. Thanks,
James
[1203 byte] By [
jpifera] at [2007-11-26 18:20:29]

# 1
What you're doing should work. That's the technique the msgsend.java
demo program uses, and it works fine for me.
Maybe I don't understand what aspect of it you don't think is working?
Certainly the debug output should include a RCPT line for each of
the recipients you list. And since you say that the message is
getting delivered to every recipient, that must be working. It's also
true that every recipient should be included in the To: header in
the message.
Maybe you can try the msgsend.java demo program and post the
output if you don't think it's working? For example, here's what I get:
$ java msgsend -d "addr1@domain.com, addr2@domain.com"
To: addr1@domain.com, addr2@domain.com
Subject: test
DEBUG: setDebug: JavaMail version 1.4.1ea
test
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
220 datsun.SFBay.Sun.COM ESMTP Sendmail 8.13.7+Sun/8.13.7; Tue, 13 Feb 2007 13:22:42 -0800 (PST)
DEBUG SMTP: connected to host "localhost", port: 25
EHLO datsun
250-datsun.SFBay.Sun.COM Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "EXPN", arg ""
DEBUG SMTP: Found extension "VERB", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "DELIVERBY", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<shannon@datsun>
250 2.1.0 <shannon@datsun>... Sender ok
RCPT TO:<addr1@domain.com>
250 2.1.5 <addr1@domain.com>... Recipient ok
RCPT TO:<addr2@domain.com>
250 2.1.5 <addr2@domain.com>... Recipient ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP:addr1@domain.com
DEBUG SMTP:addr2@domain.com
DATA
354 Enter mail, end with "." on a line by itself
Date: Tue, 13 Feb 2007 13:22:41 -0800 (PST)
From: shannon@datsun
To: addr1@domain.com, addr2@domain.com
Message-ID: <20573914.01171401762033.JavaMail.shannon@datsun>
Subject: test
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: msgsend
test
.
250 2.0.0 l1DLMg9B020736 Message accepted for delivery
QUIT
221 2.0.0 datsun.SFBay.Sun.COM closing connection
Mail was sent successfully.
# 5
duh! no, I didn't. :-(
ok, I entered in some data, hit enter, hit . so there was just one on a line by itself, then hit ^D. At that point I get the error below. The good news is that it did in fact verfiy both addresses, which I was not getting with the older javamail.
I'll have to do some searching on the error below.
thanks,
James
DATA
354 Enter mail, end with "." on a line by itself
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=us-ascii
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:851)
at javax.activation.DataHandler.writeTo(DataHandler.java:305)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1683)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:585)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at msgsend.main(msgsend.java:185)
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=us-ascii
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:625)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at msgsend.main(msgsend.java:185)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=us-ascii
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:851)
at javax.activation.DataHandler.writeTo(DataHandler.java:305)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1683)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:585)
... 3 more