v3 API C# Code Example
(information)
Info
We recommend using SendGrid C#, our client library, available on GitHub, with full documentation.
(information)
Info
Do you have an API Key yet? If not, go get one. You're going to need it to integrate!
The following example sends a single email with the Twilio SendGrid C# library. Set your API key in an environment variable, then build and send the message.
1// using SendGrid's C# Library2// https://github.com/sendgrid/sendgrid-csharp3using SendGrid;4using SendGrid.Helpers.Mail;5using System;6using System.Threading.Tasks;78namespace Example9{10internal class Example11{12private static void Main()13{14Execute().Wait();15}1617static async Task Execute()18{19var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");20var client = new SendGridClient(apiKey);21var from = new EmailAddress("test@example.com", "Example User");22var subject = "Sending with SendGrid is Fun";23var to = new EmailAddress("test@example.com", "Example User");24var plainTextContent = "and easy to do anywhere with C#.";25var htmlContent = "<strong>and easy to do anywhere with C#.</strong>";26var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);27var response = await client.SendEmailAsync(msg);28}29}30}