Last active
September 6, 2016 18:16
-
-
Save rymoore99/9091499 to your computer and use it in GitHub Desktop.
Quick Example of how easy it is to send mail using SendGrid
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.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