Created
December 18, 2014 17:21
-
-
Save Jaxmetalmax/675cf39d082b3fa4a355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void EnviaCorreoInterno(string cAsunto, List<string> destinatarios, string cBody, List<string> cAdjuntos, int port, bool ssl, string usr, string pass, string host, string correo) | |
{ | |
var mail = new MailMessage(); | |
bool succesSend = true; | |
mail.From = new MailAddress(correo); | |
var smtp = new SmtpClient | |
{ | |
Port = port, | |
EnableSsl = ssl, | |
DeliveryMethod = SmtpDeliveryMethod.Network, | |
UseDefaultCredentials = false, | |
Credentials = new NetworkCredential(usr, pass), | |
Host = host | |
}; | |
foreach (var destinatario in destinatarios) | |
{ | |
mail.To.Add((new MailAddress(destinatario))); | |
} | |
foreach (var cAdjunto in cAdjuntos) | |
{ | |
mail.Attachments.Add(new Attachment(cAdjunto)); | |
} | |
mail.IsBodyHtml = true; | |
mail.Subject = cAsunto; | |
mail.Body = cBody; | |
try | |
{ | |
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications; | |
smtp.Send(mail); | |
} | |
catch (SmtpFailedRecipientException ex) | |
{ | |
succesSend = false; | |
MessageBox.Show("Error: " + ex.Message, "Error al enviar mensaje a algun destinatario: " + ex.FailedRecipient, | |
MessageBoxButtons.OK, MessageBoxIcon.Error); | |
LogErrors.LogError(ex.Message + "\r\n" + ex.StackTrace); | |
} | |
catch (SmtpException ex) | |
{ | |
succesSend = false; | |
MessageBox.Show("Error: " + ex.Message, "Error al enviar mensaje", | |
MessageBoxButtons.OK, MessageBoxIcon.Error); | |
LogErrors.LogError(ex.Message + "\r\n" + ex.StackTrace); | |
} | |
if (succesSend) | |
Console.WriteLine("Mensaje Enviado"); | |
} | |
//Metodo para hacer una exclusion al error de certificados propios o no actualizados | |
public static bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) | |
{ | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment