473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Read in email from inbox and store it on local disks

5
can anyone plz help me to write a code to read mail from one's inbox and store the mails to the local disk??? i forgot to say it would be preferably in java..

i would be very grateful if someone could help me out in this matter.

tks in advance..

Ronald.
Feb 24 '07 #1
9 6335
baygan
5
can anyone plz help me to write a code to read mail from one's inbox and store the mails to the local disk??? i forgot to say it would be preferably in java..

i would be very grateful if someone could help me out in this matter.

tks in advance..

Ronald.
Feb 24 '07 #2
horace1
1,510 Expert 1GB
can anyone plz help me to write a code to read mail from one's inbox and store the mails to the local disk??? i forgot to say it would be preferably in java..

i would be very grateful if someone could help me out in this matter.

tks in advance..

Ronald.
have a look at the java mail API
http://java.sun.com/products/javamail/
Feb 24 '07 #3
can anyone plz help me to write a code to read mail from one's inbox and store the mails to the local disk??? i forgot to say it would be preferably in java..

i would be very grateful if someone could help me out in this matter.

tks in advance..

Ronald.


hi i am boby and i am very week in two subjects (1)vb.net (2)java2 so please would you like you help me i will be your thank full
Feb 25 '07 #4
abctech
157 100+
hi i am boby and i am very week in two subjects (1)vb.net (2)java2 so please would you like you help me i will be your thank full
Have a read at the JavaMail API first and then make an attempt at your code, post the code here if you get stuck or are getting any exceptions.

P.S : This is the Java forum, .Net posts are made in the .Net forum if you are trying to program in it.
Feb 25 '07 #5
baygan
5
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.search.*;
import javax.activation.*;


public class FetchMailUsage {

public static void main(String[] args) {

// SUBSTITUTE YOUR ISP's POP3 SERVER HERE!!!
String host = "pop.yourisp.net";
// SUBSTITUTE YOUR USERNAME AND PASSWORD TO ACCESS E-MAIL HERE!!!
String user = "your_username";
String password = "your_password";
// SUBSTITUTE YOUR SUBJECT SUBSTRING TO SEARCH HERE!!!
String subjectSubstringToSearch = "Test E-Mail through Java";

// Get a session. Use a blank Properties object.
Session session = Session.getInstance(new Properties());

try {

// Get a Store object
Store store = session.getStore("pop3");
store.connect(host, user, password);

// Get "INBOX"
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_WRITE);
int count = fldr.getMessageCount();
System.out.println(count + " total messages");

// Message numebers start at 1
for(int i = 1; i <= count; i++) {
// Get a message by its sequence number
Message m = fldr.getMessage(i);

// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);
}

// Search for e-mails by some subject substring
String pattern = subjectSubstringToSearch;
SubjectTerm st = new SubjectTerm(pattern);
// Get some message references
Message [] found = fldr.search(st);

System.out.println(found.length +
" messages matched Subject pattern \"" +
pattern + "\"");

for (int i = 0; i < found.length; i++) {
Message m = found[i];
// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);

Object o = m.getContent();
if (o instanceof String) {
System.out.println("**This is a String Message**");
System.out.println((String)o);
}
else if (o instanceof Multipart) {
System.out.print("**This is a Multipart Message. ");
Multipart mp = (Multipart)o;
int count3 = mp.getCount();
System.out.println("It has " + count3 +
" BodyParts in it**");
for (int j = 0; j < count3; j++) {
// Part are numbered starting at 0
BodyPart b = mp.getBodyPart(j);
String mimeType2 = b.getContentType();
System.out.println( "BodyPart " + (j + 1) +
" is of MimeType " + mimeType);

Object o2 = b.getContent();
if (o2 instanceof String) {
System.out.println("**This is a String BodyPart**");
System.out.println((String)o2);
}
else if (o2 instanceof Multipart) {
System.out.print(
"**This BodyPart is a nested Multipart. ");
Multipart mp2 = (Multipart)o2;
int count2 = mp2.getCount();
System.out.println("It has " + count2 +
"further BodyParts in it**");
}
else if (o2 instanceof InputStream) {
System.out.println(
"**This is an InputStream BodyPart**");
}
} //End of for
}
else if (o instanceof InputStream) {
System.out.println("**This is an InputStream message**");
InputStream is = (InputStream)o;
// Assumes character content (not binary images)
int c;
while ((c = is.read()) != -1) {
System.out.write(c);
}
}

// Uncomment to set "delete" flag on the message
//m.setFlag(Flags.Flag.DELETED,true);

} //End of for

// "true" actually deletes flagged messages from folder
fldr.close(true);
store.close();

}
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}
catch (IOException ioex) {
ioex.printStackTrace();
}

}


} //End of class

can anyone help me out by executin this code an dtellin me if it works???

plz give me a quick repl..

tks
Feb 25 '07 #6
horace1
1,510 Expert 1GB
does it work when you run it? if not what happens?
Feb 25 '07 #7
hirak1984
316 100+
LOOK AT THIS!!

please dont double post.

can anyone plz help me to write a code to read mail from one's inbox and store the mails to the local disk??? i forgot to say it would be preferably in java..

i would be very grateful if someone could help me out in this matter.

tks in advance..

Ronald.
Feb 26 '07 #8
r035198x
13,262 8TB
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.search.*;
import javax.activation.*;


public class FetchMailUsage {

public static void main(String[] args) {

// SUBSTITUTE YOUR ISP's POP3 SERVER HERE!!!
String host = "pop.yourisp.net";
// SUBSTITUTE YOUR USERNAME AND PASSWORD TO ACCESS E-MAIL HERE!!!
String user = "your_username";
String password = "your_password";
// SUBSTITUTE YOUR SUBJECT SUBSTRING TO SEARCH HERE!!!
String subjectSubstringToSearch = "Test E-Mail through Java";

// Get a session. Use a blank Properties object.
Session session = Session.getInstance(new Properties());

try {

// Get a Store object
Store store = session.getStore("pop3");
store.connect(host, user, password);

// Get "INBOX"
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_WRITE);
int count = fldr.getMessageCount();
System.out.println(count + " total messages");

// Message numebers start at 1
for(int i = 1; i <= count; i++) {
// Get a message by its sequence number
Message m = fldr.getMessage(i);

// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);
}

// Search for e-mails by some subject substring
String pattern = subjectSubstringToSearch;
SubjectTerm st = new SubjectTerm(pattern);
// Get some message references
Message [] found = fldr.search(st);

System.out.println(found.length +
" messages matched Subject pattern \"" +
pattern + "\"");

for (int i = 0; i < found.length; i++) {
Message m = found[i];
// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);

Object o = m.getContent();
if (o instanceof String) {
System.out.println("**This is a String Message**");
System.out.println((String)o);
}
else if (o instanceof Multipart) {
System.out.print("**This is a Multipart Message. ");
Multipart mp = (Multipart)o;
int count3 = mp.getCount();
System.out.println("It has " + count3 +
" BodyParts in it**");
for (int j = 0; j < count3; j++) {
// Part are numbered starting at 0
BodyPart b = mp.getBodyPart(j);
String mimeType2 = b.getContentType();
System.out.println( "BodyPart " + (j + 1) +
" is of MimeType " + mimeType);

Object o2 = b.getContent();
if (o2 instanceof String) {
System.out.println("**This is a String BodyPart**");
System.out.println((String)o2);
}
else if (o2 instanceof Multipart) {
System.out.print(
"**This BodyPart is a nested Multipart. ");
Multipart mp2 = (Multipart)o2;
int count2 = mp2.getCount();
System.out.println("It has " + count2 +
"further BodyParts in it**");
}
else if (o2 instanceof InputStream) {
System.out.println(
"**This is an InputStream BodyPart**");
}
} //End of for
}
else if (o instanceof InputStream) {
System.out.println("**This is an InputStream message**");
InputStream is = (InputStream)o;
// Assumes character content (not binary images)
int c;
while ((c = is.read()) != -1) {
System.out.write(c);
}
}

// Uncomment to set "delete" flag on the message
//m.setFlag(Flags.Flag.DELETED,true);

} //End of for

// "true" actually deletes flagged messages from folder
fldr.close(true);
store.close();

}
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}
catch (IOException ioex) {
ioex.printStackTrace();
}

}


} //End of class

can anyone help me out by executin this code an dtellin me if it works???

plz give me a quick repl..

tks
Please use code tags when posting code.

Execute the code yourself and tell us if you have any problems.
Feb 26 '07 #9
r035198x
13,262 8TB
LOOK AT THIS!!

please dont double post.
Threads merged.
Feb 26 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Chuck Amadi | last post by:
Has anyone got a simple python script that will parse a linux mbox and create a large file to view . Cheers Chu
6
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
1
by: Jim | last post by:
I'm wanting to add functionality to a website...This is for a kids sports team - would like ability for Team Managers to be able to send email and have it automatically show up on website "Inbox"...
1
by: Karen Grube | last post by:
Hi! I hate to bother you all with this, but I don't know how best to approach a particular task. Here's the deal: Once a month I personally (that is, in my own personal inbox on my...
1
by: Karen Grube | last post by:
Hi! I hate to bother you all with this, but I don't know how best to approach a particular task. Here's the deal: Once a month I personally (that is, in my own personal inbox on my...
1
by: johnfofawn | last post by:
Hi, I have an application where digital data is streamed to me at a rate of 20 MB/sec. I have 6 250GB disks totallying 1.5 TB of storage. I want to store as much data as possible and age off...
2
by: Karen Grube | last post by:
Hi! I hate to bother you all with this, but I don't know how best to approach a particular task. Here's the deal: Once a month I receive in my own inbox on my company's Outlook Exchange...
62
by: Bryan Dickerson | last post by:
Is there a way, with VS 2005 and FX 2.0, to read a given inbox? I need to write a 'monitor' program and my boss is convinced, as is always his first gut reaction, that we need to go buy a...
3
by: GayathriP | last post by:
This article discusses about how can we access the inbox through MAPI using C# .NET. It also discusses about how to store the attachment in the local directory, how to create a folder in the inbox ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.