Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Mail

 
L.John
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to All,
I am using Java Mail API, and for testing purpose, i am giving my own email id for sender and receiver both
I am ruuning a Daemon which actually gets a batch of lets say 20 records from the database and for each record an email has to be send to someone(In this case Receiver is me ). The first email i get is fine , the second one and subsequent emails i get , lets say, the daemon extracted the 5th record, so when i am sent an email for the fifth record . I have the following:

From:LJohn To:LJohn;LJohn;LJohn;LJohn;LJohn;
Sub:You have got mail Cc:

Now I would like to know can i get rid of this problem of Recepient.Type (i.e my name being repeted the number of times equal to the number of records going to be fetched from the database).
It would be kind of you to let me know , how can i avoid my name to be appended or added to the existing one .
My code is as follows:
-------------------------
props = new Properties();
props.put(protocol,host);
s = Session.getInstance(props);
message = new MimeMessage(s);
InternetAddress from =new InternetAddress(SEND_MAIL_FROM_ADMIN);
message.setFrom(from);
InternetAddress to = new InternetAddress(email_id);// a string .
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject(subject);
String matter = "Hello ! This is checking the working of the Java Mail API for Request ID:" + requestid;
message.setText(matter);
Transport.send(message);
Thanks ,

Kind Regards,
John

 
Yogen Vadnere
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why dont u use for all address except first emailId
Message.RecipientType.BCC
 
L.John
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yogen,
Thanks for replying to my query.
I am not really clear about what you suggested to me. Here the Recepient Type I have is TO.
It would be kind of you to tell me more about what you meant by it .
Thanks,
Regards,
John
why dont u use for all address except first emailId
Message.RecipientType.BCC
 
Tom Ben
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look like here
InternetAddress to = new InternetAddress(email_id);// a string
message.addRecipient(Message.RecipientType.TO, to);

If email_id is just a string with a new email address each time for each different document this you do not need the (InternetAddress to = new InternetAddress(email_id)
Just update the email_id with the new email address or this case just yours once and say (message.addRecipient(Message.RecipientType.TO, email_id)
the object "to" is being casted up to an Address array. So maybe that is why you are getting your email address over and over again. I do not use InternetAddress unless I am sending more than one person an email.
------------------
Sun Certified Programmer on the Java 2 Platform
 
Tom Ben
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look like here
InternetAddress to = new InternetAddress(email_id);// a string
message.addRecipient(Message.RecipientType.TO, to);

If email_id is just a string with a new email address each time for each different document this you do not need the (InternetAddress to = new InternetAddress(email_id)
Just update the email_id with the new email address or this case just yours once and say (message.addRecipient(Message.RecipientType.TO, email_id)
the object "to" is being casted up to an Address array. So maybe that is why you are getting your email address over and over again. I do not use InternetAddress unless I am sending more than one person an email.
------------------
Sun Certified Programmer on the Java 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic