This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hide All recipients email address

 
varun bihani
Ranch Hand
Posts: 96
  • 0
  • 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="";
//out.println(subject);
boolean sent = false;
Properties props = new Properties();
props.setProperty("mail.smtp.host", mailHost);
Session ssn = Session.getDefaultInstance(props);
ssn.setDebug(true);
Message msg = new MimeMessage(ssn);
int i=0;
try{
StringTokenizer st = new StringTokenizer(to,",");
String[] totalrec=new String[10];
while (st.hasMoreTokens())
{
totalrec[i]= st.nextToken();
out.println("recepients"+i+":"+totalrec[i]);
i++;
}
InternetAddress fromAdd = new InternetAddress(from);
msg.setFrom(fromAdd);
msg.setSubject(subject);
InternetAddress[] toAdd = new InternetAddress[i];
for (int j = 0; j < i; j++)
{
toAdd[j] = new InternetAddress(totalrec[j]);
System.out.println("Rec"+j+":"+toAdd[j]);
}
msg.setRecipients(Message.RecipientType.TO, toAdd);
msg.setContent(body, "text/html");
Transport.send(msg);
sent = true;

System.out.println("FROM2:"+fromAdd+"\n\n");
}catch(Exception e)
{
out.println("Error:\n\n"+e);
}
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic