Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hide All recipients email address  RSS feed

varun bihani
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able to send html format mail using javamail.
but I want to send mail to multiple users at the same time.
so i have stored email addresses in an array but i dont want to display all the email addresses on the TO field in the recipients mail box. I only want to that the reciepient see that the mail has been sent to him only..
My code goes something like this..
String to=request.getParameter("to");
String from=request.getParameter("from");
String subject=request.getParameter("subject");
String body=request.getParameter("body");
String mailHost="";
boolean sent = false;
Properties props = new Properties();
props.setProperty("", mailHost);
Session ssn = Session.getDefaultInstance(props);
Message msg = new MimeMessage(ssn);
int i=0;
StringTokenizer st = new StringTokenizer(to,",");
String[] totalrec=new String[10];
while (st.hasMoreTokens())
totalrec[i]= st.nextToken();
InternetAddress fromAdd = new InternetAddress(from);
InternetAddress[] toAdd = new InternetAddress[i];
for (int j = 0; j < i; j++)
toAdd[j] = new InternetAddress(totalrec[j]);
msg.setRecipients(Message.RecipientType.TO, toAdd);
msg.setContent(body, "text/html");
sent = true;

}catch(Exception e)
Dirk Schreckmann
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you want to send the message to yourself and then BCC (blind carbon copy) each recipient. Take a look at the Message class and the Message.RecipientType class documentations.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!