static void SendMail(SendMailConfig config, SendMailContext context) { var client = new SmtpSocketClient(config.Smtp, config.Port, config.From, config.Password); client.SslType = config.SslEnabled ? SslMode.Ssl : SslMode.Auto; var mail = new MimeMailMessage(); mail.From = new System.Net.Mail.MailAddress(context.DisplayName ?? config.From); mail.Sender = new System.Net.Mail.MailAddress(config.From); mail.To.Add(context.To); mail.IsBodyHtml = context.IsBodyHtml; mail.Subject = context.Subject; mail.Body = context.Body; mail.BodyEncoding = Encoding.UTF8; foreach (var attachment in context.Attachments) { mail.Attachments.Add(new MimeAttachment(attachment)); } client.SendMail(mail); }
static void Main(string[] args) { SendMail(SendMailConfig.LoadFromAppConfig(), SendMailContext.LoadFromArgs(args)); }