Permalink
Browse files

added examples based on user feedback

  • Loading branch information...
1 parent a4c59ce commit 9b04e9c45445883508b699af481fd7c076ee0d17 @tbischel tbischel committed Jan 25, 2012
@@ -16,18 +16,19 @@ static void Main(string[] args)
{
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
var smtpapi = new SMTPAPI(username, password, from, to);
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();
View
@@ -421,5 +421,126 @@ public void EnableBypassListManagementEmail()
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);
+ }
+
}
}
View
@@ -421,5 +421,128 @@ public void EnableBypassListManagementEmail()
//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);
+ }
+
}
}
@@ -104,7 +104,7 @@ public interface ISendGrid
/// 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
@@ -288,7 +288,7 @@ public void AddSubVal(String replacementTag, List<String> substitutionValues)
Header.AddSubVal(replacementTag, substitutionValues);
}
- public void AddUniqueIdentifier(IDictionary<String, String> identifiers)
+ public void AddUniqueIdentifiers(IDictionary<String, String> identifiers)
{
Header.AddUniqueIdentifier(identifiers);
}
@@ -119,7 +119,7 @@ public void TestAddUniqueIdentifier()
var mock = new Mock<IHeader>();
var sg = new SendGrid(mock.Object);
- sg.AddUniqueIdentifier(kvp);
+ sg.AddUniqueIdentifiers(kvp);
mock.Verify(foo => foo.AddUniqueIdentifier(kvp));
}

0 comments on commit 9b04e9c

Please sign in to comment.