static void Main(string[] args) { // Instantiate the email wrapper EmailWrapper new_email = new EmailWrapper(); // Parse the args and pass the email wrapper ParseArgs(args, ref new_email); // Send Email int result = new_email.Send(); Environment.Exit(result); }
private static void ParseArgs(string[] args, ref EmailWrapper email) { //Read each argument int args_count = args.Length; if (args_count <= 0) { PrintHelpMenu(); } for (int i = 0; i < args_count; i++) { switch (args[i]) { case "-h": case "--help": PrintHelpMenu(); break; case "-a": //Attachments case "--attachment": // Split the next argument by semicolons and commas if (i + 1 < args_count) { foreach (string att in args[i + 1].Split(new Char[] { ',', ';' })) { email.AddAttachment(att); } i++; } else { Console.WriteLine("No argument proceeding the attachments list [-a]"); PrintHelpMenu(); } break; case "-b": // Email body case "--body": if (i + 1 < args_count) { email.body = args[i + 1]; i++; } else { Console.WriteLine("No argument proceeding the body argument [-b]"); PrintHelpMenu(); } break; case "-g": // Distribution Groups case "--group": // Split the next argument by semicolons and commas if (i + 1 < args_count) { foreach (string grp in args[i + 1].Split(new Char[] { ',', ';' })) { email.AddGroup(grp); } i++; } else { Console.WriteLine("No argument proceeding the distrubution group list [-g]"); PrintHelpMenu(); } break; case "-i": //Inline Attachments case "--inline": // Split the next argument by semicolons and commas if (i + 1 < args_count) { foreach (string s in args[i + 1].Split(',')) { email.AddInlineAttachment(s); } i++; } else { Console.WriteLine("No argument proceeding the attachments list [-a]"); PrintHelpMenu(); } //Console.WriteLine("Inline attachments not yet supported"); i++; break; case "-t": // Recipients case "--to": if (i + 1 < args_count) { foreach (string t in args[i + 1].Split(new Char[] { ',', ';' })) { email.AddRecipient(t); } i++; } else { Console.WriteLine("No argument proceeding the recipients list [-t]"); PrintHelpMenu(); } break; case "-s": //Subject Line case "--subject": if (i + 1 < args_count) { email.subject = args[i + 1]; i++; } else { Console.WriteLine("No argument proceeding the subject argument [-s]"); PrintHelpMenu(); } break; case "-f": // Sender case "--from": if (i + 1 < args_count) { email.sender = args[i + 1]; i++; } else { Console.WriteLine("No argument proceeding the from argument [-f]"); PrintHelpMenu(); } break; case "-w": // Use HTML Template case "--web": if (i + 1 < args_count) { email.UseHTML(args[i + 1]); i++; } else { Console.WriteLine("No argument proceeding the from argument [-w]"); PrintHelpMenu(); } break; default: Console.WriteLine("Invaild input: {0}", args[i]); PrintHelpMenu(); break; } } }