Skip to content

Commit ae1a5fd

Browse files
Merge pull request #486 from sendgrid/singleemailsinglerecipient
Add Send a Single Email to a Single Recipient example
2 parents 2331602 + de5d17e commit ae1a5fd

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

USE_CASES.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ This documentation provides examples for specific use cases. Please [open an iss
22

33
# Table of Contents
44

5-
* [Attachments](#attachments)
6-
* [Kitchen Sink - an example with all settings used](#kitchensink)
7-
* [Transactional Templates](#transactional_templates)
5+
* [Email - Attachments](#attachments)
6+
* [Email - Kitchen Sink - an example with all settings used](#kitchensink)
7+
* [Email - Send a Single Email to a Single Recipient](#singleemailsinglerecipient)
8+
* [Email - Transactional Templates](#transactional_templates)
89

910
<a name="attachments"></a>
1011
# Attachments
@@ -27,7 +28,7 @@ namespace Example
2728

2829
static async Task Execute()
2930
{
30-
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
31+
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
3132
var client = new SendGridClient(apiKey);
3233
var from = new EmailAddress("[email protected]");
3334
var subject = "Subject";
@@ -53,9 +54,9 @@ using System;
5354
using System.Threading.Tasks;
5455
using System.Collections.Generic;
5556

56-
namespace KitchenSink
57+
namespace Example
5758
{
58-
internal class KitchenSink
59+
internal class Example
5960
{
6061
private static void Main()
6162
{
@@ -64,7 +65,7 @@ namespace KitchenSink
6465

6566
static async Task Execute()
6667
{
67-
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
68+
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
6869
var client = new SendGridClient(apiKey);
6970
var msg = new SendGridMessage();
7071

@@ -306,6 +307,40 @@ namespace KitchenSink
306307
}
307308
```
308309

310+
<a name="singleemailsinglerecipient"></a>
311+
# Send a Single Email to a Single Recipient
312+
313+
```csharp
314+
using SendGrid;
315+
using SendGrid.Helpers.Mail;
316+
using System;
317+
using System.Threading.Tasks;
318+
319+
namespace Example
320+
{
321+
internal class Example
322+
{
323+
private static void Main()
324+
{
325+
Execute().Wait();
326+
}
327+
328+
static async Task Execute()
329+
{
330+
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
331+
var client = new SendGridClient(apiKey);
332+
var from = new EmailAddress("[email protected]", "Example User");
333+
var subject = "Sending with SendGrid is Fun";
334+
var to = new EmailAddress("[email protected]", "Example User");
335+
var plainTextContent = "and easy to do anywhere, even with C#";
336+
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
337+
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
338+
var response = await client.SendEmailAsync(msg);
339+
}
340+
}
341+
}
342+
```
343+
309344
<a name="transactional_templates"></a>
310345
# Transactional Templates
311346

0 commit comments

Comments
 (0)