recipients)
{
_username = username;
_password = password;
@@ -46,8 +46,8 @@ public void SimpleHTMLEmail()
//set the message subject
message.Subject = "Hello World HTML Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//send the mail
transportInstance.Deliver(message);
@@ -76,8 +76,8 @@ public void SimplePlaintextEmail()
//set the message subject
message.Subject = "Hello World Plain Text Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//send the mail
transportInstance.Deliver(message);
@@ -108,8 +108,8 @@ public void EnableGravatarEmail()
//set the message subject
message.Subject = "Hello World Gravatar Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//enable gravatar
message.EnableGravatar();
@@ -142,8 +142,8 @@ public void EnableOpenTrackingEmail()
//set the message subject
message.Subject = "Hello World Open Tracking Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//enable gravatar
message.EnableOpenTracking();
@@ -181,8 +181,8 @@ public void EnableClickTrackingEmail()
//set the message subject
message.Subject = "Hello World Click Tracking Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//enable clicktracking
message.EnableClickTracking(false);
@@ -218,8 +218,8 @@ public void EnableSpamCheckEmail()
//set the message subject
message.Subject = "WIN A MILLION DOLLARS TODAY! WORK FROM HOME! A NIGERIAN PRINCE WANTS YOU!";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//enable spamcheck
message.EnableSpamCheck();
@@ -255,8 +255,8 @@ public void EnableUnsubscribeEmail()
//set the message subject
message.Subject = "Hello World Unsubscribe Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//enable spamcheck
//or optionally, you can specify 'replace' instead of the text and html in order to
@@ -295,8 +295,8 @@ public void EnableFooterEmail()
//set the message subject
message.Subject = "Hello World Footer Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//Enable Footer
message.EnableFooter("PLAIN TEXT FOOTER", "HTML FOOTER TEXT
");
@@ -334,8 +334,8 @@ public void EnableGoogleAnalytics()
//set the message subject
message.Subject = "Hello World Footer Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//enable Google Analytics
message.EnableGoogleAnalytics("SendGridTest", "EMAIL", "Sendgrid", "ad-one", "My SG Campaign");
@@ -373,8 +373,8 @@ public void EnableTemplateEmail()
//set the message subject
message.Subject = "Hello World Template Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//enable template
message.EnableTemplate("My Email Template <% body %> is awesome!
");
@@ -412,8 +412,8 @@ public void EnableBypassListManagementEmail()
//set the message subject
message.Subject = "Hello World Bypass List Management Test";
- //create an instance of the REST transport mechanism
- var transportInstance = REST.GetInstance(new NetworkCredential(_username, _password));
+ //create an instance of the Web transport mechanism
+ var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
//enable bypass list management
message.EnableBypassListManagement();
@@ -421,5 +421,128 @@ public void EnableBypassListManagementEmail()
//send the mail
transportInstance.Deliver(message);
}
+
+
+ ///
+ /// This feature allows you to create a message template, and specify different replacement
+ /// strings for each specific recipient
+ ///
+ 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 { "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);
+ }
+
+ ///
+ /// This feature adds key value identifiers to be sent back as arguments over the event api for
+ /// various events
+ ///
+ 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();
+ 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);
+
+ }
+
+ ///
+ /// This feature tags the message with a specific tracking category, which will have aggregated stats
+ /// viewable from your SendGrid account page.
+ ///
+ 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 08d109cf5..a96e93c5f 100755
--- a/SendGrid/SendGridMail/ISendGrid.cs
+++ b/SendGrid/SendGridMail/ISendGrid.cs
@@ -1,20 +1,11 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Net;
using System.Net.Mail;
namespace SendGridMail
{
- ///
- /// Internal object to represent the way in which email may be sent.
- /// The library supports sending through either SMTP or REST interfaces.
- ///
- public enum TransportType
- {
- SMTP,
- REST
- };
-
///
/// Represents the basic set of functions that will be called by the user
/// includes basic message data manipulation and filter settings
@@ -27,13 +18,13 @@ public interface ISendGrid
MailAddress[] Cc { get; }
MailAddress[] Bcc { get; }
MailAddress[] ReplyTo { get; set; }
+ Dictionary StreamedAttachments { get; set; }
String[] Attachments { get; set; }
String Subject { get; set; }
Dictionary Headers { get; set; }
IHeader Header { get; set; }
String Html { get; set; }
String Text { get; set; }
- TransportType Transport { get; set; }
#endregion
#region Interface for ITransport
@@ -42,13 +33,6 @@ public interface ISendGrid
///
/// MIME to be sent
MailMessage CreateMimeMessage();
-
- ///
- /// Creates a new transport object, and sends this message out.
- ///
- /// Sendgrid user credentials
- void Mail(NetworkCredential credentials);
-
#endregion
#region Methods for setting data
@@ -68,7 +52,7 @@ public interface ISendGrid
/// Add to the 'To' address.
///
/// the dictionary keys are the email addresses, which points to a dictionary of
- /// key value pairs mapping to other address codes, such as { foo@bar.com => { 'DisplayName' => 'Mr Foo' } }
+ /// key substitutionValues pairs mapping to other address codes, such as { foo@bar.com => { 'DisplayName' => 'Mr Foo' } }
void AddTo(IDictionary> addresssInfo);
///
@@ -87,7 +71,7 @@ public interface ISendGrid
/// Add to the 'CC' address.
///
/// the dictionary keys are the email addresses, which points to a dictionary of
- /// key value pairs mapping to other address codes, such as { foo@bar.com => { 'DisplayName' => 'Mr Foo' } }
+ /// key substitutionValues pairs mapping to other address codes, such as { foo@bar.com => { 'DisplayName' => 'Mr Foo' } }
void AddCc(IDictionary> addresssInfo);
///
@@ -106,16 +90,30 @@ public interface ISendGrid
/// Add to the 'Bcc' address.
///
/// the dictionary keys are the email addresses, which points to a dictionary of
- /// key value pairs mapping to other address codes, such as { foo@bar.com => { 'DisplayName' => 'Mr Foo' } }
+ /// key substitutionValues pairs mapping to other address codes, such as { foo@bar.com => { 'DisplayName' => 'Mr Foo' } }
void AddBcc(IDictionary> addresssInfo);
///
- /// Adds a substitution value to be used during the mail merge. Substitutions will happen in the order
- /// added, so calls to this should match calls to addTo.
+ /// Defines a mapping between a replacement string in the text of the message to a list of
+ /// substitution values to be used, one per each recipient, in the same order as the recipients were added.
///
- /// the string in the email that you'll replace eg. '-name-'
- /// a list of values that will be substituted in for the tag, one for each recipient
- void AddSubVal(String tag, params String[] value);
+ /// the string in the email that you'll replace eg. '-name-'
+ /// a list of values that will be substituted in for the replacementTag, one for each recipient
+ void AddSubVal(String replacementTag, List substitutionValues);
+
+ ///
+ /// This adds parameters and values that will be bassed back through SendGrid's
+ /// Event API if an event notification is triggered by this email.
+ ///
+ /// parameter substitutionValues pairs to be passed back on event notification
+ void AddUniqueIdentifiers(IDictionary identifiers);
+
+ ///
+ /// This sets the category for this email. Statistics are stored on a per category
+ /// basis, so this can be useful for tracking on a per group basis.
+ ///
+ /// categories applied to the message
+ void SetCategory(String category);
///
/// Add an attachment to the message.
@@ -123,6 +121,13 @@ public interface ISendGrid
/// a fully qualified file path as a string
void AddAttachment(String filePath);
+ ///
+ /// Add a stream as an attachment to the message
+ ///
+ /// Stream of file to be attached
+ /// Name of file to be attached
+ void AddAttachment(Stream stream, String name);
+
///
/// GetRecipients returns a list of all the recepients by retrieving the to, cc, and bcc lists.
///
@@ -132,7 +137,7 @@ public interface ISendGrid
///
/// Add custom headers to the message
///
- /// key value pairs
+ /// key substitutionValues pairs
void AddHeaders(IDictionary headers);
#endregion
@@ -206,7 +211,7 @@ public interface ISendGrid
///
/// Provides notification when emails are deteched that exceed a predefined spam threshold.
///
- /// Emails with a SpamAssassin score over this value will be considered spam and not be delivered.
+ /// Emails with a SpamAssassin score over this substitutionValues will be considered spam and not be delivered.
/// SendGrid will send an HTTP POST request to this url when a message is detected as spam
void EnableSpamCheck(int score = 5, String url = null);
@@ -243,7 +248,7 @@ public interface ISendGrid
///
/// Wraps an HTML template around your email content.
///
- /// HTML that your emails will be wrapped in, containing a body tag.
+ /// HTML that your emails will be wrapped in, containing a body replacementTag.
void EnableTemplate(String html = null);
///
diff --git a/SendGrid/SendGridMail/Mail.csproj b/SendGrid/SendGridMail/Mail.csproj
index bd1dc7a99..91d3b9192 100755
--- a/SendGrid/SendGridMail/Mail.csproj
+++ b/SendGrid/SendGridMail/Mail.csproj
@@ -53,8 +53,9 @@
+
-
+