Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

v3 API C# Code Example


(information)

Info

We recommend using SendGrid C#, our client library, available on GitHub(link takes you to an external page), with full documentation.

(information)

Info

Do you have an API Key(link takes you to an external page) yet? If not, go get one. You're going to need it to integrate!


Using SendGrid's C# Library

using-sendgrids-c-library page anchor

_30
// using SendGrid's C# Library
_30
// https://github.com/sendgrid/sendgrid-csharp
_30
using SendGrid;
_30
using SendGrid.Helpers.Mail;
_30
using System;
_30
using System.Threading.Tasks;
_30
_30
namespace Example
_30
{
_30
internal class Example
_30
{
_30
private static void Main()
_30
{
_30
Execute().Wait();
_30
}
_30
_30
static async Task Execute()
_30
{
_30
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
_30
var client = new SendGridClient(apiKey);
_30
var from = new EmailAddress("test@example.com", "Example User");
_30
var subject = "Sending with SendGrid is Fun";
_30
var to = new EmailAddress("test@example.com", "Example User");
_30
var plainTextContent = "and easy to do anywhere with C#.";
_30
var htmlContent = "<strong>and easy to do anywhere with C#.</strong>";
_30
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
_30
var response = await client.SendEmailAsync(msg);
_30
}
_30
}
_30
}


Rate this page: