Example #1
0
        private string sendmail(MailMessage _mailMessage)
        {
            using (SmtpClient smtpClient = new SmtpClient(ServerConfig.SmtpAdress, (int)ServerConfig.SmtpPort))
            {
                var cryptograph = new AESEncription();

                smtpClient.EnableSsl             = true;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtpClient.Credentials           = new NetworkCredential(ServerConfig.SmtpUsername, cryptograph.DecryptMensage(ServerConfig.SmtpPassword));
                try
                {
                    smtpClient.Send(_mailMessage);
                    return("Email Entregue com Sucesso");
                }
                catch (SmtpFailedRecipientsException ex)
                {
                    //var retmsg = "";
                    //for (int i = 0; i < ex.InnerExceptions.Length; i++)
                    //{
                    //    SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
                    //    return string.Format("Failed to deliver message to {0}", ex.InnerExceptions[i].FailedRecipient);
                    //}
                    return(ex.Message);
                }
                catch (Exception ex)
                {
                    return(string.Format("Exception caught in RetryIfBusy(): {0}", ex.Message.ToString()));
                }
            }
        }