• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i read mail content using Java Mail ApI

 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic