Last active
February 14, 2017 12:15
-
-
Save sendgrid-gists/96491eb186b73b5c00756ad9195f3a0b to your computer and use it in GitHub Desktop.
v3 "Hello World" for email, using SendGrid with C#.
This file contains hidden or 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 SendGrid's C# Library | |
// https://github.com/sendgrid/sendgrid-csharp | |
using SendGrid; | |
using SendGrid.Helpers.Mail; | |
using System; | |
using System.Threading.Tasks; | |
namespace Example | |
{ | |
internal class Example | |
{ | |
private static void Main() | |
{ | |
Execute().Wait(); | |
} | |
static async Task Execute() | |
{ | |
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY"); | |
var client = new SendGridClient(apiKey); | |
var from = new EmailAddress("[email protected]", "Example User"); | |
var subject = "Sending with SendGrid is Fun"; | |
var to = new EmailAddress("[email protected]", "Example User"); | |
var plainTextContent = "and easy to do anywhere, even with C#"; | |
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>"; | |
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); | |
var response = await client.SendEmailAsync(msg); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment