Read all recipient mail address from PST outlook file using Java Mail API


public void getOriginalMailRecipientAddresses(PSTMessage email){
ORIGINAL_MAIL_TO="";
ORIGINAL_MAIL_CC="";
ORIGINAL_MAIL_BCC="";
   try {
for(int i=0;i<email.getNumberOfRecipients();i++){
if(email.getRecipient(i).getEmailAddress().contains("@") && email.getRecipient(i).getRecipientType()==1){
ORIGINAL_MAIL_TO+=email.getRecipient(i).getEmailAddress()+", ";
}
else if(email.getRecipient(i).getEmailAddress().contains("@") && email.getRecipient(i).getRecipientType()==2){
ORIGINAL_MAIL_CC+=email.getRecipient(i).getEmailAddress()+", ";
}
else if(email.getRecipient(i).getEmailAddress().contains("@") && email.getRecipient(i).getRecipientType()==3){
ORIGINAL_MAIL_BCC+=email.getRecipient(i).getEmailAddress()+", ";
}else{
System.out.println("Not a valid recipient:not found@");
ORIGINAL_MAIL_TO="<none>";
}
}
if(ORIGINAL_MAIL_TO != null && ORIGINAL_MAIL_TO.trim().length()>0){
ORIGINAL_MAIL_TO=ORIGINAL_MAIL_TO.substring(0,ORIGINAL_MAIL_TO.lastIndexOf(','));
}
if(ORIGINAL_MAIL_CC != null && ORIGINAL_MAIL_CC.trim().length()>0){
ORIGINAL_MAIL_CC=ORIGINAL_MAIL_CC.substring(0,ORIGINAL_MAIL_CC.lastIndexOf(','));
}
if(ORIGINAL_MAIL_BCC != null && ORIGINAL_MAIL_BCC.trim().length()>0){
ORIGINAL_MAIL_BCC=ORIGINAL_MAIL_BCC.substring(0,ORIGINAL_MAIL_BCC.lastIndexOf(','));
}
System.out.println("ORIGINAL_MAIL_TO:"+ORIGINAL_MAIL_TO);
System.out.println("ORIGINAL_MAIL_CC:"+ORIGINAL_MAIL_CC);
System.out.println("ORIGINAL_MAIL_BCC:"+ORIGINAL_MAIL_BCC);

} catch (PSTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
---------------------------------------------------------------------------------------------
This is the code snippet which will help you if you are reading mails from pst file. You can refer the example   from our blog http://knowledge-serve.blogspot.com/2011/09/how-to-read-mail-from-outlook-pst-file.html

Comments

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

How to create mail message in FRC822 format