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
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply 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: 137
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: 32768
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.


Android appsImageJ pluginsJava web charts
Muneeswaran Balasubramanian
Ranch Hand

Joined: Mar 19, 2010
Posts: 137
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
 
 
subject: How can i read mail content using Java Mail ApI
 
Threads others viewed
saving attachments with javamail
problem reading the mail Attachment
Java mail attachmetnt include txt extensions
Getting Multiple Attachments from MIMEMessage
Upload Excel using IO and servlet
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture