It's not a secret anymore!
The moose likes Other JSE/JEE APIs and the fly likes send a single email to a distribution list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "send a single email to a distribution list" Watch "send a single email to a distribution list" New topic

send a single email to a distribution list

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
using java program, is it possible to send only one email to a whole distribution list? Meaning...

the to field in the email has all the email addresses from the distribution list. This single email is sent out to everybody in the distribution list, rather than a single email/person in the list.

SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
In the JavaMail API -which is what you'd use to send emails from Java- you'll see that the Message class has addRecipient methods that let you add multiple email addresses at the same time, so what you're asking can be done.

However, putting all recipients in the To field is considered very bad practice - it exposes all addresses to everybody, which has consequences both concerning security and privacy. You really should not do that. It's much better to program a loop and send those emails individually.
[ January 22, 2008: Message edited by: Ulf Dittmer ]
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Putting all recipients into the BCC field would solve the privacy problems. But there are other advantages to sending one e-mail per recipient. For example, if there was a badly-formed address in your list, your server might not send messages to all of the other well-formed addresses. You would have to do some testing and fiddling about to make sure you knew how that would work and how it could be made reliable.
I agree. Here's the link:
subject: send a single email to a distribution list
It's not a secret anymore!