• Post Reply Bookmark Topic Watch Topic
  • New Topic

receiving attachments using javamail  RSS feed

vidhya subramaniam
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 vidhya.subramaniam@omnifax.xerox.com
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 = System.in;
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
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vidhya subramaniam:

See the PDF this has an example to read email with attachment at the end. http://www.jaydeetechnology.co.uk/planetjava/tutorials/language/javamail2.pdf
I never used it.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!