Skip to content

Instantly share code, notes, and snippets.

@rymoore99
Last active September 6, 2016 18:16
Show Gist options
  • Save rymoore99/9091499 to your computer and use it in GitHub Desktop.
Save rymoore99/9091499 to your computer and use it in GitHub Desktop.
Quick Example of how easy it is to send mail using SendGrid
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using SendGridMail;
public class SendGridEmailService
{
public bool Send(string toAddress, string fromAddress, string fromAddressAlias, string subject, string body)
{
try
{
var myMessage = SendGrid.GetInstance();
myMessage.AddTo(toAddress);
myMessage.From = new MailAddress(fromAddress, fromAddressAlias);
myMessage.Subject = subject;
myMessage.Html = body;
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential("username", "password");
// Create a Web transport for sending email.
var transportWeb = Web.GetInstance(credentials);
// Send the email.
transportWeb.Deliver(myMessage);
return true;
}
catch (Exception e)
{
// TODO: Log this
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment