This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Save email body content in a file on disk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Save email body content in a file on disk" Watch "Save email body content in a file on disk" New topic
Author

Save email body content in a file on disk

Andrew Vyas
Greenhorn

Joined: Mar 19, 2008
Posts: 3
Hello, I'm new to this Forum and first of all i would really like to thank all of you for providing such a nice and sorted facility to post our doubts. I really appreciate this...

Now i'm working with emails and i have created a routine to extract a signature out of the entire mail body. But now i have been allotted a task to use javamail and access my gmail account and from there extract the email's body and save it in a file on my computer and then call my routine on that file so that the signature out of it is extracted. So i just needed some code to save my gmail email's body in some file on my disk. I've tried to search for it but i'm not getting something useful.

So if anyone can please provide me a working and simple code for this task to extract the email body from gmail and save it in a file on my computer, i'll really be very greatful. Thanking you...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, first you download JavaMail. (You may already have done this.) Then you look in the "demo" folder of your download, where there is a lot of sample programs. The one you're looking for as the basis of your code is "msgshow.java".
Andrew Vyas
Greenhorn

Joined: Mar 19, 2008
Posts: 3
Hi Mr. Paul. I'm very thankful that you replied and i also tried to run the msgshow.java file in the demo folder and it gets compiled nicely but when it comes the time to run, it gives me exceptions.
I am runnig it with the following command

java msgshow -T imap -H pop.gmail.com -U my_id@gmail.com -P pwd -f INBOX 1

But on doing this i'm getting the exception...

javax.mail.MessagingException: Connection timed out: connect;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:571)
at javax.mail.Service.connect(Service.java:288)
at msgshow.mail(msgshow.java:162)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.PlainSocketImpl.connect(Socket.java:519)
at java.net.PlainSocketImpl.connect(Socket.java:469)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:107)
at com.sun.mail.imap.protocol.IMAPProtocol<init>(IMAPProtocol.java:104)

at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
... 2 more

This is what i'm getting. I will be very delighted if you can solve this or else give me some simple code for gmail mail storage. Thanking you...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Don't make the mistake of thinking that code is everything. The error message means your computer can't connect to pop.gmail.com. That's something to do with your network configuration and no amount of programming will change that. Talk to the person who connected your computer to the network and ask them what can be done.

It's possible that the network is configured to prevent you from making that connection. However your network specialist should be able to tell you that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Save email body content in a file on disk
 
Similar Threads
save and load JPEG image from disk
how to invalidate a session from another computer by using ip/MAC sessionid
Looking for an order-of-magnitude speed-up
How to open a local file in Java program
Problems with a batch process using Java+Unix