· 6 years ago · Feb 01, 2020, 06:24 PM
1static void Main(string[] args)
2 {
3 Execute().Wait();
4 }
5 static async Task Execute()
6 {
7 // Retrieve the API key from the environment variables. See the project README for more info about setting this up.
8 var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
9
10 var client = new SendGridClient(apiKey);
11
12 // Send a Single Email using the Mail Helper
13 var from = new EmailAddress("jovan.prodanovic20@gmail.com", "Jovan Prodanovic");
14 var subject = "Hello World!";
15 var to = new EmailAddress("jovan.prod1996@gmail.com", "Jovan Prod");
16 var plainTextContent = "Hello!";
17 var htmlContent = "<strong>Hello!</strong>";
18 var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
19
20 var response = await client.SendEmailAsync(msg);
21 Console.WriteLine(msg.Serialize());
22 Console.WriteLine(response.StatusCode);
23 Console.WriteLine(response.Headers);
24 Console.WriteLine("\n\nPress <Enter> to continue.");
25 Console.ReadLine();
26 }