diff options
author | Tyler Bischel <tyler.bischel@sendgrid.com> | 2012-01-24 16:30:29 -0800 |
---|---|---|
committer | Tyler Bischel <tyler.bischel@sendgrid.com> | 2012-01-24 16:30:29 -0800 |
commit | 9b04e9c45445883508b699af481fd7c076ee0d17 (patch) | |
tree | 73695bb9fa31d0996168402c8d6568813848e802 | |
parent | a4c59ce574fa71bd7d2096b4a142e8d54670ea3c (diff) | |
download | sendgrid-csharp-9b04e9c45445883508b699af481fd7c076ee0d17.zip sendgrid-csharp-9b04e9c45445883508b699af481fd7c076ee0d17.tar.gz sendgrid-csharp-9b04e9c45445883508b699af481fd7c076ee0d17.tar.bz2 |
added examples based on user feedback
-rwxr-xr-x | SendGrid/Example/Program.cs | 7 | ||||
-rwxr-xr-x | SendGrid/Example/SMTPAPI.cs | 121 | ||||
-rwxr-xr-x | SendGrid/Example/WEBAPI.cs | 123 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/ISendGrid.cs | 2 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/SendGrid.cs | 2 | ||||
-rwxr-xr-x | SendGrid/Tests/TestSendgridMessageSetup.cs | 2 |
6 files changed, 251 insertions, 6 deletions
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs index a429510..edec5c9 100755 --- a/SendGrid/Example/Program.cs +++ b/SendGrid/Example/Program.cs @@ -16,10 +16,11 @@ namespace Example {
var username = "sgrid_username";
var password = "sgrid_password";
- var from = "cj.buchmann@sendgrid.com";
+ var from = "bar@domain.com";
var to = new List<String>
{
- "foo@bar.com"
+ "foo@domain.com",
+ "raz@domain.com"
};
//initialize the SMTPAPI example class
@@ -27,7 +28,7 @@ namespace Example var restapi = new WEBAPI(username, password, from, to);
//use this section to test out our Web and SMTP examples!
- restapi.EnableTemplateEmail();
+ smtpapi.SimpleHTMLEmail();
Console.WriteLine("Done!");
Console.ReadLine();
diff --git a/SendGrid/Example/SMTPAPI.cs b/SendGrid/Example/SMTPAPI.cs index ca80f69..d9ab154 100755 --- a/SendGrid/Example/SMTPAPI.cs +++ b/SendGrid/Example/SMTPAPI.cs @@ -421,5 +421,126 @@ namespace Example transportInstance.Deliver(message);
}
+ /// <summary>
+ /// This feature allows you to create a message template, and specify different replacement
+ /// strings for each specific recipient
+ /// </summary>
+ public void AddSubstitutionValues()
+ {
+ //create a new message object
+ var message = SendGrid.GetInstance();
+
+ //set the message recipients
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ message.Text = "Hi %name%! Pleased to meet you!";
+
+ //set the message subject
+ message.Subject = "Testing Substitution Values";
+
+ //This replacement key must exist in the message body
+ var replacementKey = "%name%";
+
+ //There should be one value for each recipient in the To list
+ var substitutionValues = new List<String> {"Mr Foo", "Mrs Raz"};
+
+ message.AddSubVal(replacementKey, substitutionValues);
+
+ //create an instance of the SMTP transport mechanism
+ var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
+
+ //enable bypass list management
+ message.EnableBypassListManagement();
+
+ //send the mail
+ transportInstance.Deliver(message);
+ }
+
+ /// <summary>
+ /// This feature adds key value identifiers to be sent back as arguments over the event api for
+ /// various events
+ /// </summary>
+ public void AddUniqueIdentifiers()
+ {
+ //create a new message object
+ var message = SendGrid.GetInstance();
+
+ //set the message recipients
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ message.Text = "Hello World";
+
+ //set the message subject
+ message.Subject = "Testing Unique Identifiers";
+
+ var identifiers = new Dictionary<String, String>();
+ identifiers["customer"] = "someone";
+ identifiers["location"] = "somewhere";
+
+ message.AddUniqueIdentifiers(identifiers);
+
+ //create an instance of the SMTP transport mechanism
+ var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
+
+ //enable bypass list management
+ message.EnableBypassListManagement();
+
+ //send the mail
+ transportInstance.Deliver(message);
+
+ }
+
+ /// <summary>
+ /// This feature tags the message with a specific tracking category, which will have aggregated stats
+ /// viewable from your SendGrid account page.
+ /// </summary>
+ public void SetCategory()
+ {
+ //create a new message object
+ var message = SendGrid.GetInstance();
+
+ //set the message recipients
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ message.Text = "Hello World";
+
+ //set the message subject
+ message.Subject = "Testing Categories";
+
+ var category = "vipCustomers";
+
+ message.SetCategory(category);
+
+ //create an instance of the SMTP transport mechanism
+ var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
+
+ //enable bypass list management
+ message.EnableBypassListManagement();
+
+ //send the mail
+ transportInstance.Deliver(message);
+ }
+
}
}
diff --git a/SendGrid/Example/WEBAPI.cs b/SendGrid/Example/WEBAPI.cs index adfd756..985005d 100755 --- a/SendGrid/Example/WEBAPI.cs +++ b/SendGrid/Example/WEBAPI.cs @@ -421,5 +421,128 @@ namespace Example //send the mail
transportInstance.Deliver(message);
}
+
+
+ /// <summary>
+ /// This feature allows you to create a message template, and specify different replacement
+ /// strings for each specific recipient
+ /// </summary>
+ public void AddSubstitutionValues()
+ {
+ //create a new message object
+ var message = SendGrid.GetInstance();
+
+ //set the message recipients
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ message.Text = "Hi %name%! Pleased to meet you!";
+
+ //set the message subject
+ message.Subject = "Testing Substitution Values";
+
+ //This replacement key must exist in the message body
+ var replacementKey = "%name%";
+
+ //There should be one value for each recipient in the To list
+ var substitutionValues = new List<String> { "Mr Foo", "Mrs Raz" };
+
+ message.AddSubVal(replacementKey, substitutionValues);
+
+ //create an instance of the SMTP transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
+
+ //enable bypass list management
+ message.EnableBypassListManagement();
+
+ //send the mail
+ transportInstance.Deliver(message);
+ }
+
+ /// <summary>
+ /// This feature adds key value identifiers to be sent back as arguments over the event api for
+ /// various events
+ /// </summary>
+ public void AddUniqueIdentifiers()
+ {
+ //create a new message object
+ var message = SendGrid.GetInstance();
+
+ //set the message recipients
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ message.Text = "Hello World";
+
+ //set the message subject
+ message.Subject = "Testing Unique Identifiers";
+
+ var identifiers = new Dictionary<String, String>();
+ identifiers["customer"] = "someone";
+ identifiers["location"] = "somewhere";
+
+ message.AddUniqueIdentifiers(identifiers);
+
+ //create an instance of the SMTP transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
+
+ //enable bypass list management
+ message.EnableBypassListManagement();
+
+ //send the mail
+ transportInstance.Deliver(message);
+
+ }
+
+ /// <summary>
+ /// This feature tags the message with a specific tracking category, which will have aggregated stats
+ /// viewable from your SendGrid account page.
+ /// </summary>
+ public void SetCategory()
+ {
+ //create a new message object
+ var message = SendGrid.GetInstance();
+
+ //set the message recipients
+ foreach (string recipient in _to)
+ {
+ message.AddTo(recipient);
+ }
+
+ //set the sender
+ message.From = new MailAddress(_from);
+
+ //set the message body
+ message.Text = "Hello World";
+
+ //set the message subject
+ message.Subject = "Testing Categories";
+
+ var category = "vipCustomers";
+
+ message.SetCategory(category);
+
+ //create an instance of the SMTP transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
+
+ //enable bypass list management
+ message.EnableBypassListManagement();
+
+ //send the mail
+ transportInstance.Deliver(message);
+ }
+
}
}
diff --git a/SendGrid/SendGridMail/ISendGrid.cs b/SendGrid/SendGridMail/ISendGrid.cs index 724d145..10f0826 100755 --- a/SendGrid/SendGridMail/ISendGrid.cs +++ b/SendGrid/SendGridMail/ISendGrid.cs @@ -104,7 +104,7 @@ namespace SendGridMail /// Event API if an event notification is triggered by this email.
/// </summary>
/// <param name="identifiers">parameter substitutionValues pairs to be passed back on event notification</param>
- void AddUniqueIdentifier(IDictionary<String, String> identifiers);
+ void AddUniqueIdentifiers(IDictionary<String, String> identifiers);
/// <summary>
/// This sets the category for this email. Statistics are stored on a per category
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs index 5f847dc..e3b992f 100755 --- a/SendGrid/SendGridMail/SendGrid.cs +++ b/SendGrid/SendGridMail/SendGrid.cs @@ -288,7 +288,7 @@ namespace SendGridMail Header.AddSubVal(replacementTag, substitutionValues);
}
- public void AddUniqueIdentifier(IDictionary<String, String> identifiers)
+ public void AddUniqueIdentifiers(IDictionary<String, String> identifiers)
{
Header.AddUniqueIdentifier(identifiers);
}
diff --git a/SendGrid/Tests/TestSendgridMessageSetup.cs b/SendGrid/Tests/TestSendgridMessageSetup.cs index 474b03f..fa3db72 100755 --- a/SendGrid/Tests/TestSendgridMessageSetup.cs +++ b/SendGrid/Tests/TestSendgridMessageSetup.cs @@ -119,7 +119,7 @@ namespace Tests var mock = new Mock<IHeader>();
var sg = new SendGrid(mock.Object);
- sg.AddUniqueIdentifier(kvp);
+ sg.AddUniqueIdentifiers(kvp);
mock.Verify(foo => foo.AddUniqueIdentifier(kvp));
}
|