using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SendGrid;
using SendGrid.Helpers.Mail;
using System.Collections.Generic;
namespace Example
{
internal class Example
{
private static void Main()
{
Execute().Wait();
}
static async Task Execute()
{
string apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
Client client = new Client(apiKey);
// Send a Single Email using the Mail Helper
var from = new MailAddress("dx@sendgrid", "DX Team");
var subject = "Hello World from the SendGrid CSharp Library Helper!";
var to = new MailAddress("elmer@sendgrid.com", "Elmer Thomas");
var contentText = "Hello, Email from the helper [SendSingleEmailAsync]!";
var contentHTML = "Hello, Email from the helper! [SendSingleEmailAsync]";
Response response = await client.Mail.SendSingleEmailAsync(from, to, subject , contentText, contentHTML);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.ReadLine();
// Without the Mail Helper
string data = @"{
'personalizations': [
{
'to': [
{
'email': 'elmer@sendgrid.com'
}
],
'subject': 'Hello World from the SendGrid C# Library!'
}
],
'from': {
'email': 'dx@sendgrid.com'
},
'content': [
{
'type': 'text/plain',
'value': 'Hello, Email!'
}
]
}";
Object json = JsonConvert.DeserializeObject