Skip to content

Instantly share code, notes, and snippets.

@Jaxmetalmax
Created December 18, 2014 17:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaxmetalmax/675cf39d082b3fa4a355 to your computer and use it in GitHub Desktop.
Save Jaxmetalmax/675cf39d082b3fa4a355 to your computer and use it in GitHub Desktop.
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