-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example file stream usage in USE_CASES.md
- Loading branch information
1 parent
6525eaa
commit babd710
Showing
1 changed file
with
21 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,11 @@ namespace Example | |
{ | ||
private static void Main() | ||
{ | ||
Execute().Wait(); | ||
ExecuteManualAttachmentAdd().Wait(); | ||
ExecuteStreamAttachmentAdd().Wait(); | ||
} | ||
|
||
static async Task Execute() | ||
static async Task ExecuteManualAttachmentAdd() | ||
{ | ||
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY"); | ||
var client = new SendGridClient(apiKey); | ||
|
@@ -45,6 +46,23 @@ namespace Example | |
msg.AddAttachment("file.txt", file); | ||
var response = await client.SendEmailAsync(msg); | ||
} | ||
|
||
static async Task ExecuteStreamAttachmentAdd() | ||
{ | ||
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY"); | ||
var client = new SendGridClient(apiKey); | ||
var from = new EmailAddress("[email protected]"); | ||
var subject = "Subject"; | ||
var to = new EmailAddress("[email protected]"); | ||
var body = "Email Body"; | ||
var msg = MailHelper.CreateSingleEmail(from, to, subject, body, ""); | ||
|
||
using (var fileStream = File.OpenRead("/Users/username/file.txt")) | ||
{ | ||
msg.AddAttachment("file.txt", fileStream); | ||
var response = await client.SendEmailAsync(msg); | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
@@ -656,4 +674,4 @@ Find more information about all of SendGrid's whitelabeling realated doucmentati | |
|
||
You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics) and via API [here](https://github.com/sendgrid/sendgrid-csharp/blob/master/USAGE.md#stats). | ||
|
||
Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as SendGrid processes your email. | ||
Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as SendGrid processes your email. |