-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update add attachment interface #522
Merged
thinkingserious
merged 9 commits into
sendgrid:master
from
shortstuffsushi:update-add-attachment-interface
Nov 28, 2017
+411
−34
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4f637e8
First pass cleanup.
shortstuffsushi 43b1b1f
Update param description.
shortstuffsushi 869af03
Add method for adding attachment streams.
shortstuffsushi 2709194
Remove extra logic around length.
shortstuffsushi 0540d7c
Whoops, this didn't go through on the last commit.
shortstuffsushi 89f89af
Null / empty check.
shortstuffsushi d266816
Clean up usings so I can compile.
shortstuffsushi 6525eaa
Add a bunch of tests around the AddAttachment methods.
shortstuffsushi babd710
Add example file stream usage in USE_CASES.md
shortstuffsushi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. |
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.IO; | ||
|
||
namespace SendGrid.Tests.Helpers.Mail | ||
{ | ||
|
||
public class NonReadableStream : Stream | ||
{ | ||
public override bool CanRead => false; | ||
|
||
public override bool CanSeek => throw new System.NotImplementedException(); | ||
|
||
public override bool CanWrite => throw new System.NotImplementedException(); | ||
|
||
public override long Length => throw new System.NotImplementedException(); | ||
|
||
public override long Position { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } | ||
|
||
public override void Flush() | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public override void SetLength(long value) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like using the
IEnumerable
here, but I'm concerned about breaking changes by removing the old function signature. How about keeping the old function signature and adding this one as a function overload?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
List
inherits fromIEnumerable
, this shouldn't be a breaking change. Anyone using lists should see things continue to work as though nothing changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks for the super quick response :)