Skip to content

Commit

Permalink
Add example file stream usage in USE_CASES.md
Browse files Browse the repository at this point in the history
  • Loading branch information
shortstuffsushi committed Nov 6, 2017
1 parent 6525eaa commit babd710
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions USE_CASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
}
}
```
Expand Down Expand Up @@ -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.

0 comments on commit babd710

Please sign in to comment.