CommandLineParser parser = new GnuParser ();
Options options = new Options ();
options.addOption (new HelpOption ());
FromEmailOption fromOption = new FromEmailOption ();
options.addOption (fromOption);
ToEmailOption toOption = new ToEmailOption ();
options.addOption (toOption);
options.addOption (new SubjectOption ());
options.addOption (new FileOption ());
try {
// parse the command line arguments
CommandLine line = parser.parse (options, args);
if (line.hasOption (HelpOption.cValue)) {
HelpFormatter hf = new HelpFormatter ();
hf.printHelp (SendMessage.class.toString (), options);
}
else {
File file = null;
if (line.hasOption (FileOption.cValue)) {
file = new File (line.getOptionValue (FileOption.cValue));
}
InternetAddress from = fromOption.parse (line);
InternetAddress to = toOption.parse (line);
String subject = line.getOptionValue (SubjectOption.cValue);
SendMessage sm = new SendMessage ();
sm.send (from, to, subject, file);