diff options
-rwxr-xr-x | .gitignore | 4 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/Header.cs | 13 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/IHeader.cs | 12 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/SendGrid.cs | 4 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/Transport/Web.cs | 6 | ||||
-rwxr-xr-x | SendGrid/Tests/TestSendgridMessageSetup.cs | 12 |
6 files changed, 45 insertions, 6 deletions
@@ -11,4 +11,6 @@ SendGrid/Example/bin/ SendGrid/Example/obj/ SendGrid/*/bin/ SendGrid/*/obj/ - +SendGrid/Tests/test-results/ +SendGrid/test-results/ +.DS_store diff --git a/SendGrid/SendGridMail/Header.cs b/SendGrid/SendGridMail/Header.cs index f1328f5..be4ebeb 100755 --- a/SendGrid/SendGridMail/Header.cs +++ b/SendGrid/SendGridMail/Header.cs @@ -15,12 +15,25 @@ namespace SendGridMail _settings = new HeaderSettingsNode();
}
+ public IEnumerable<string> To
+ {
+ get
+ {
+ return _settings.GetArray("to");
+ }
+ }
+
public void AddSubVal(string tag, IEnumerable<string> substitutions)
{
var keys = new List<String> {"sub", tag};
_settings.AddArray(keys, substitutions);
}
+ public void AddTo(IEnumerable<string> addresses)
+ {
+ _settings.AddArray(new List<string> { "to" }, addresses);
+ }
+
public void AddUniqueIdentifier(IDictionary<string, string> identifiers)
{
foreach (var key in identifiers.Keys)
diff --git a/SendGrid/SendGridMail/IHeader.cs b/SendGrid/SendGridMail/IHeader.cs index f55eadd..3ec7911 100755 --- a/SendGrid/SendGridMail/IHeader.cs +++ b/SendGrid/SendGridMail/IHeader.cs @@ -11,6 +11,11 @@ namespace SendGridMail /// </summary>
public interface IHeader
{
+ /// <summary>
+ /// Gets the array of recipient addresses from the X-SMTPAPI header
+ /// </summary>
+ IEnumerable<string> To { get; }
+
/// <summary>
/// This adds a substitution value to be used during the mail merge. Substitutions
/// will happen in order added, so calls to this should match calls to addTo in the mail message.
@@ -20,6 +25,13 @@ namespace SendGridMail void AddSubVal(String tag, IEnumerable<String> substitutions);
/// <summary>
+ /// This adds the "to" array to the X-SMTPAPI header so that multiple recipients
+ /// may be addressed in a single email. (but they each get their own email, instead of a single email with multiple TO: addressees)
+ /// </summary>
+ /// <param name="addresses">List of email addresses</param>
+ void AddTo(IEnumerable<string> addresses);
+
+ /// <summary>
/// This adds parameters and values that will be bassed back through SendGrid's
/// Event API if an event notification is triggered by this email.
/// </summary>
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs index 4a14211..3f2878f 100755 --- a/SendGrid/SendGridMail/SendGrid.cs +++ b/SendGrid/SendGridMail/SendGrid.cs @@ -305,14 +305,14 @@ namespace SendGridMail {
Header.SetCategory(category);
}
-
+ public void AddAttachment(Stream stream, String name)
{
MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);
StreamedAttachments[name] = ms;
}
-
+ public void AddAttachment(String filePath)
{
_attachments.Add(filePath);
diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs index f3448ad..5a27469 100755 --- a/SendGrid/SendGridMail/Transport/Web.cs +++ b/SendGrid/SendGridMail/Transport/Web.cs @@ -84,11 +84,11 @@ namespace SendGridMail.Transport private void AttachFiles(ISendGrid message, MultipartEntity multipartEntity)
{
- var files = FetchFileBodies(message);
- files.ForEach(kvp => multipartEntity.AddBody(new FileBody("files[" + Path.GetFileName(kvp.Key) + "]", kvp.Key, kvp.Value)));
+ var files = FetchFileBodies(message); + files.ForEach(kvp => multipartEntity.AddBody(new FileBody("files[" + Path.GetFileName(kvp.Key) + "]", Path.GetFileName(kvp.Key), kvp.Value)));
var streamingFiles = FetchStreamingFileBodies(message);
- streamingFiles.ForEach(kvp => multipartEntity.AddBody(new StreamedFileBody(kvp.Value, kvp.Key)));
+ streamingFiles.ForEach(kvp => multipartEntity.AddBody(new StreamedFileBody(kvp.Value, kvp.Key))); }
private void CheckForErrors(CodeScales.Http.Methods.HttpResponse response)
diff --git a/SendGrid/Tests/TestSendgridMessageSetup.cs b/SendGrid/Tests/TestSendgridMessageSetup.cs index fa3db72..ea57eb7 100755 --- a/SendGrid/Tests/TestSendgridMessageSetup.cs +++ b/SendGrid/Tests/TestSendgridMessageSetup.cs @@ -12,6 +12,18 @@ namespace Tests [TestFixture]
public class TestSendgridMessageSetup
{
+ [Test]
+ public void TestAddHeaderTo()
+ {
+ var mock = new Mock<Header>();
+ var sg = new SendGrid(mock.Object);
+
+ var strings = new string[2] {"eric@sendgrid.com", "tyler@sendgrid.com"};
+ sg.Header.AddTo(strings);
+ Assert.AreEqual(strings, sg.Header.To, "check the X-Smtpapi to array");
+ }
+
+
[Test]
public void TestAddTo()
{
|