Created
February 17, 2014 13:39
-
-
Save fabriciosanchez/9050625 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
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.Net.Mail; | |
using System.Net.Mime; | |
... | |
public bool EnviaMensagemComSendGrid() | |
{ | |
try | |
{ | |
MailMessage Mensagem = new MailMessage(); | |
Mensagem.To.Add(new MailAddress("{E-mail do destinatário}", "{Nome do destinatário}")); | |
Mensagem.From = new MailAddress("{E-mail do remetente}", "{Nome do remetente}"); | |
Mensagem.Subject = "{Assunto da mensagem}"; | |
string Texto = "{Corpo da mensagem}"; | |
string HTML = @"<p>Mensagem HTML</p>"; | |
Mensagem.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(Texto, null, MediaTypeNames.Text.Plain)); | |
Mensagem.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(HTML, null, MediaTypeNames.Text.Html)); | |
SmtpClient SMTP = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587)); | |
System.Net.NetworkCredential Credenciais = new System.Net.NetworkCredential("{Nome de usuário}", "{Senha}"); | |
SMTP.Credentials = Credenciais; | |
SMTP.Send(Mensagem); | |
return true; | |
} | |
catch (Exception ex) | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment