• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question on Java Mail

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
In a code like this (it works fine)

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

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

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!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)

p
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see everything now.
Thanks a lot!
 
please buy my thing and then I'll have more money:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic