• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Mail  RSS feed

 
rawkaw Ra
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Members,

I am sending Mail using JavaMail API. It behaves odd.

Let me explain this..

Theme: I've to take the email-id's and mail-message from SQLDB and
send the mail-message to email-id's . This operation is iterative for n number of rows.

Problem:
1. For single iterative process its working fine ie 1 row its good
But if no of rows i fetched is more than 1,it sending the appropriate message as Mail and the previous message as Attachment.

code :

programs starts

main method
{

// DB connection code here

Query1 = ( select message,subject,to from DB where condition )
ResultSet = Statement.executeQuery(Query1);

while(ResultSet)
{
mess=ResultSet.getString("message");
sub=ResultSet.getString("subject");
add[]=ResultSet.getString("to").split(";");

Mail.composeHead(sub,add);
Mail.composeBody(mess,"text/plain");
}

}

composeHead
-----------
public void composeHead(String subject, List receiverlist)
throws MessagingException {

Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
InternetAddress addresses[] = new InternetAddress[receiverlist.s
ize()];
for (int i = 0; i < addresses.length; i++) {
String receiver = (String) receiverlist.get(i);
addresses[i] = new InternetAddress(receiver);
}

message = new MimeMessage(session);
message.setSubject(subject);
message.setFrom(new InternetAddress(sender));
message.addRecipients(Message.RecipientType.TO, addresses);
}

composeBody
----------------
public void composeBody(String coverfilename, String type) throws Except
ion {
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(coverfilename, type);
multipart.addBodyPart(messageBodyPart);
}






Can any body please help me in this regards,
 
saravanan balu
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
after u got the resultset, you have put something like

By right, it supposed to be
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!