Skip to content

Instantly share code, notes, and snippets.

@nesticle8bit
Last active May 29, 2019 13:20
Show Gist options
  • Save nesticle8bit/a1bb7a4ffcfaee55e338bf26597c9370 to your computer and use it in GitHub Desktop.
Save nesticle8bit/a1bb7a4ffcfaee55e338bf26597c9370 to your computer and use it in GitHub Desktop.
Enviar correos electronicos
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
var credentialUserName = ConfigurationManager.AppSettings.Get("IPS.Email.Email");
var sentFrom = credentialUserName;
var pwd = ConfigurationManager.AppSettings.Get("IPS.Email.Password");
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings.Get("IPS.Email.SMTP"))
{
Port = Convert.ToInt32(ConfigurationManager.AppSettings.Get("IPS.Email.Port")),
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false
};
NetworkCredential credentials = new NetworkCredential(credentialUserName, pwd);
client.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IPS.Email.SSL"));
client.Credentials = credentials;
MailMessage mail = new MailMessage(sentFrom, message.Destination)
{
Subject = message.Subject,
Body = message.Body,
IsBodyHtml = true
};
return client.SendMailAsync(mail);
}
}
<add key="IPS.Email.Email" value="" />
<add key="IPS.Email.Password" value="" />
<add key="IPS.Email.SMTP" value="smtp.gmail.com" />
<add key="IPS.Email.Port" value="587" />
<add key="IPS.Email.SSL" value="true" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment