Showing message with webservice
The requirement is like Dot net environment needs to call a webservice to access mails of a certain user from java mail.
I wrote a webservice that connects to IMAP and able to fetch certain message details. The webservice returns a string(say resultString
) which includes details like From, Size, Received date and subject.
But, the challenging task is how is that I return a message?Since message could be of single part or multipart, If the message is in text format I could append it to string resultString
and return. But what if the message has attachments? How would and what should I be returning in that case?
I hope I made my point clear. Has any one have any suggestion. I appreciate and solicit your great idea.
Thanks.
Rk.
Heres the sample webservice i wrote:
public String displayDet(String hostname,String userEmail,String password)
throws Exception{
try{
m_MailSession = Session.getInstance(System.getProperties(),null);
//setup store and connect to it
String proto ="imap";
m_Store = m_MailSession.getStore(proto);
m_Username=userEmail;
m_PostOfficeHost=hostname;
m_Store.connect(m_PostOfficeHost,m_Username,password);
System.out.println(m_Username+"@"+m_PostOfficeHost+"SUCCESSFUL LOGIN");
m_Inbox = m_Store.getFolder("INBOX");
}catch (Exception e){e.printStackTrace();}
String resultString;
StringBuffer sbf =new StringBuffer();
m_Inbox.open(Folder.READ_ONLY);
Message msg[] = m_Inbox.getMessages();
for(int index=0;index<msg.length;index++){
sbf.append("From : "+msg[index].getFrom());//to be modified
sbf.append(",");
sbf.append("Message no. "+index+" Subject :"+msg[index].getSubject());
sbf.append(",");
sbf.append("Date :"+msg[index].getReceivedDate());
sbf.append(",");
sbf.append(",");
sbf.append("Size :"+msg[index].getSize());
sbf.append(",");
//sbf.append("Message body) :"+msg[index].getBody());
//sbf.append(",");
}
m_Inbox.close(false);
try{//close store
m_Store.close();}catch (Exception ex){ex.printStackTrace();}
resultString=sbf.toString();
return resultString;
}//displayDet
>

