Exemple #1
0
        public static void Send(string subject, string message, string to, string from = null)
        {
            MailMessage mailMessage = new MailMessage
            {
                IsBodyHtml = true,
                From       = new MailAddress(from ?? MixService.GetSmtpConfig <string>("From"))
            };

            mailMessage.To.Add(to);
            mailMessage.Body    = message;
            mailMessage.Subject = subject;
            try
            {
                SmtpClient client = new SmtpClient(MixService.GetSmtpConfig <string>("Server"))
                {
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(
                        MixService.GetSmtpConfig <string>("User"), MixService.GetSmtpConfig <string>("Password")
                        ),
                    Port      = MixService.GetSmtpConfig <int>("Port"),
                    EnableSsl = MixService.GetSmtpConfig <bool>("SSL")
                };

                client.SendAsync(mailMessage, Guid.NewGuid().ToString());
            }
            catch (Exception e)
            {
                MixService.LogException(e);
            }
        }