Skip to content

Instantly share code, notes, and snippets.

@fabriciosanchez
Created February 17, 2014 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabriciosanchez/9050625 to your computer and use it in GitHub Desktop.
Save fabriciosanchez/9050625 to your computer and use it in GitHub Desktop.
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