It's not a secret anymore!
The moose likes Beginning Java and the fly likes A question on Java Mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A question on Java Mail" Watch "A question on Java Mail" New topic

A question on Java Mail

fedai gandjaliyev
Ranch Hand

Joined: Dec 05, 2005
Posts: 99
In a code like this (it works fine)

Properties props = new Properties();
props.put("mail.transfer.protocol", "smtp");
props.put("", "my_smtp_server");
props.put("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("");
msg.setReceipent(new InternetAddress("");
msg.setSubject("A saying");
msg.setContent("Be careful what you wish for, you might get it");

I need to add 37 receipents to my receipents' list.
What can you advice to me to make it faster?
Maybe by creating a session object for each receipent and
letting it run into a separate thread.
Any suggestions?
Thank you very much!
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Instead of using setRecipient, you can use addRecipients to add as many as you need. If you want to send out multiple emails (one to each recipient), simply iterate the code you have, settting a new recipient each time. There's no need to start a new session for each email.
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
what did you try ? why do you think you need/can make it faster ?

did you have a look at the public void addRecipient(Message.RecipientType type,Address address) method in Message ? you can add all the recipients at once (of course only if they all receive the same email)

fedai gandjaliyev
Ranch Hand

Joined: Dec 05, 2005
Posts: 99
I see everything now.
Thanks a lot!
I agree. Here's the link:
subject: A question on Java Mail
It's not a secret anymore!