//0.1 - 08/20/2013 - Initial Coding //0.2 - 12/12/2016 - Added the option for CC and BCC lines //0.3 - 01/25/2017 - Added authentication support, Logging tag, function rewrite //0.4 - 09/20/2017 - Compiled for .net v4.5 //0.5 - 03/28/2018 - Add option to save/use default password. static void Main(string[] args) { smtparg SmtpArg = new smtparg(args); if (args.Length == 0) { ShowInfo(); return; } //Console.WriteLine("my password: " +SmtpArg.Password); if (SmtpArg.AllowSend) { SendMail(SmtpArg); } }
static void SendMail(smtparg sa) { MailMessage myMessage = new MailMessage(sa.FromAddress, sa.ToAddress, sa.Subject, sa.Body); if (!(sa.Attachment == "")) { if (sa.WillLog) { System.Console.WriteLine("Attaching " + sa.Attachment); } Attachment data = new Attachment(sa.Attachment); myMessage.Attachments.Add(data); } if (!String.IsNullOrEmpty(sa.CCAddress)) { myMessage.CC.Add(sa.CCAddress); } if (!String.IsNullOrEmpty(sa.BCCAddress)) { myMessage.Bcc.Add(sa.BCCAddress); } SmtpClient smtpClient = new SmtpClient(sa.Server); smtpClient.Port = sa.Port; if (!(String.IsNullOrEmpty(sa.Username)) && !(String.IsNullOrEmpty(sa.Password))) { smtpClient.Credentials = new System.Net.NetworkCredential(sa.Username, sa.Password); } try { smtpClient.Send(myMessage); } catch (Exception ex) { System.Console.WriteLine("Error: " + ex.ToString()); } }