File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes receiving attachments using javamail 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 "receiving attachments using javamail" Watch "receiving attachments using javamail" New topic

receiving attachments using javamail

vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
I have 2 doubts ....
Firstly, I would like to save attachments in a dir using javamail. I found some sample codes for receiving messages in the javamail package but not anything for saving the files. What additional do I have to add in my receiving messages code?
If someone have any source code can you please send it to me. You can even mail me at
Secondly the code that I use to receive messages goes like this
public class msgshow {
static String protocol;
static String host = null;
static String user = null;
static String password = null;
static String mbox = "INBOX";
static String url = null;
static int port = -1;
static boolean verbose = false;
static boolean debug = false;
static boolean showStructure = false;
static boolean showMessage = false;
static boolean showAlert = false;
static boolean saveAttachments = false;
static int attnum = 1;
public static void main(String argv[]) {
int msgnum = -1;
int optind;
InputStream msgStream =;
for (optind = 0; optind < argv.length; optind++) {
if (argv[optind].equals("-T")) {
protocol = argv[++optind];
} else if (argv[optind].equals("-H")) {
host = argv[++optind];
} else if (argv[optind].equals("-U")) {
user = argv[++optind];
} else if (argv[optind].equals("-P")) {
password = argv[++optind];
} else if (argv[optind].equals("-v")) {
verbose = true;
} else if (argv[optind].equals("-D")) {
debug = true;
} else if (argv[optind].equals("-f")) {
mbox = argv[++optind];
} else if (argv[optind].equals("-L")) {
url = argv[++optind];
} else if (argv[optind].equals("-p")) {
port = Integer.parseInt(argv[++optind]);
} else if (argv[optind].equals("-s")) {
showStructure = true;
} else if (argv[optind].equals("-S")) {
saveAttachments = true;
} else if (argv[optind].equals("-m")) {
showMessage = true;
} else if (argv[optind].equals("-a")) {
showAlert = true;
} else if (argv[optind].equals("--")) {
} else if (argv[optind].startsWith("-")) {
"Usage: msgshow [-L url] [-T protocol] [-H host] [-p port] [-U user]");
"\t[-P password] [-f mailbox] [msgnum] [-v] [-D] [-s] [-S] [-a]");
"or msgshow -m [-v] [-D] [-s] [-S] < msg");
} else {
Can someone explain what the comparison with 's',S,'T','H','P', etc stand for?
Balaji Loganathan
author and deputy

Joined: Jul 13, 2001
Posts: 3150
Originally posted by vidhya subramaniam:

See the PDF this has an example to read email with attachment at the end.
I never used it.

Spritle Software Blogs
I agree. Here's the link:
subject: receiving attachments using javamail
It's not a secret anymore!