aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes How can i read mail content using Java Mail ApI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "How can i read mail content using Java Mail ApI" Watch "How can i read mail content using Java Mail ApI" New topic
Author

How can i read mail content using Java Mail ApI

Muneeswaran Balasubramanian
Ranch Hand

Joined: Mar 19, 2010
Posts: 138
Hi to all,
I have wrote code to read mail from Gmail.I have read the mail content using Mime message.At that time i face one difficulty that is i can't read the exact content from Mail.The mail content contains the html contents also.How can i get the exact content from mail.Code for read the content is
public void getContent()
{
Multipart mp = (Multipart) msg.getContent();

int count = mp.getCount();
for (int i = 0; i < count; i++)
{
dumpPart(mp.getBodyPart(i));
}
}
public void dumpPart(Part p) throws Exception
{
InputStream is = p.getInputStream();

if (!(is instanceof BufferedInputStream))
{
is = new BufferedInputStream(is);
}
int c;
System.out.println("Message : ");
while ((c = is.read()) != -1)
{
System.out.write(c);
}
}
please try to solve my problem.Thanks in advance.


Cheers Munees
My Blog
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Not sure what you mean by "the exact content" - are you saying that the code returns something other than what's in the mail? That would sound like a bug.

Or are you saying that it returns HTML when you actually want just the plain text? If so, you can use a library like TagSoup to access the text components of the HTML. That's outside the scope of JavaMail.


Ping & DNS - my free Android networking tools app
Muneeswaran Balasubramanian
Ranch Hand

Joined: Mar 19, 2010
Posts: 138
Hi sheriff,
Thanks for your reply.You are correct i actually want just the plain text.But it contents html tags also.you said to use tagsoup for get html content only.I will try to do it.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i read mail content using Java Mail ApI