diff options
26 files changed, 126 insertions, 1643 deletions
diff --git a/SendGrid/Example/Example.csproj b/SendGrid/Example/Example.csproj index 97a47b4..808592c 100644 --- a/SendGrid/Example/Example.csproj +++ b/SendGrid/Example/Example.csproj @@ -50,19 +50,18 @@ <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WEBAPI.cs" />
- <Compile Include="SMTPAPI.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\SendGridMail\Mail.csproj">
- <Project>{3C687BEF-FF50-44AD-8315-2D4237281AF8}</Project>
- <Name>Mail</Name>
- </ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\SendGridMail\Mail.csproj">
+ <Project>{3c687bef-ff50-44ad-8315-2d4237281af8}</Project>
+ <Name>Mail</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs index 7ab96d4..4ebb895 100644 --- a/SendGrid/Example/Program.cs +++ b/SendGrid/Example/Program.cs @@ -2,7 +2,6 @@ using System.Net;
using System.Net.Mail;
using SendGridMail;
-using SendGridMail.Transport;
namespace Example
{
diff --git a/SendGrid/Example/SMTPAPI.cs b/SendGrid/Example/SMTPAPI.cs deleted file mode 100755 index 28120d3..0000000 --- a/SendGrid/Example/SMTPAPI.cs +++ /dev/null @@ -1,545 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Net;
-using System.Net.Mail;
-using SendGridMail;
-using SendGridMail.Transport;
-
-namespace Example
-{
- class SMTPAPI
- {
- private String _username;
- private String _password;
- private String _from;
- private IEnumerable<String> _to;
-
- public SMTPAPI(String username, String password, String from, IEnumerable<String> recipients)
- {
- _username = username;
- _password = password;
- _from = from;
- _to = recipients;
- }
-
- /// <summary>
- /// Send a simple HTML based email
- /// </summary>
- public void SimpleHTMLEmail()
- {
- //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.Html = "<html><p>Hello</p><p>World</p></html>";
-
- //set the message subject
- message.Subject = "Hello World HTML Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// Send a simple Plain Text email
- /// </summary>
- public void SimplePlaintextEmail()
- {
- //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 Plain Text";
-
- //set the message subject
- message.Subject = "Hello World Plain Text Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// Enable The Gravatar Filter.
- /// Currently the filter generates a 1x1 pixel gravatar image.
- /// http://docs.sendgrid.com/documentation/apps/gravatar/
- /// </summary>
- public void EnableGravatarEmail()
- {
- //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.Html = "<p style='color:red';>Hello World Gravatar Email</p>";
-
- //set the message subject
- message.Subject = "Hello World Gravatar Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //enable gravatar
- message.EnableGravatar();
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// Enable the Open Tracking to track when emails are opened.
- /// http://docs.sendgrid.com/documentation/apps/open-tracking/
- /// </summary>
- public void EnableOpenTrackingEmail()
- {
- //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.Html = "<p style='color:red';>Hello World Plain Text</p>";
-
- //set the message subject
- message.Subject = "Hello World Open Tracking Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //enable gravatar
- message.EnableOpenTracking();
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// Point the urls to Sendgrid Servers so that the clicks can be logged before
- /// being directed to the appropriate link
- /// http://docs.sendgrid.com/documentation/apps/click-tracking/
- /// </summary>
- public void EnableClickTrackingEmail()
- {
- //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
- var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
- message.Html = "<p style='color:red';>Hello World HTML </p> <a href='http://microsoft.com'>Checkout Microsoft!!</a>";
- message.Html += "<p>Sent At : " + timestamp + "</p>";
-
- message.Text = "hello world http://microsoft.com";
-
- //set the message subject
- message.Subject = "Hello World Click Tracking Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //enable clicktracking
- message.EnableClickTracking(false);
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// The Spam Checker filter, is useful when your web application allows your end users
- /// to create content that is then emailed through your SendGrid account.
- /// http://docs.sendgrid.com/documentation/apps/spam-checker-filter/
- /// </summary>
- public void EnableSpamCheckEmail()
- {
- //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
- var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
- message.Html = "<p style='color:red';>VIAGRA!!!!!! Viagra!!! CHECKOUT THIS VIAGRA!!!! MALE ENHANCEMENT!!! </p>";
- message.Html += "<p>Sent At : " + timestamp + "</p>";
-
- //set the message subject
- message.Subject = "WIN A MILLION DOLLARS TODAY! WORK FROM HOME! A NIGERIAN PRINCE WANTS YOU!";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //enable spamcheck
- message.EnableSpamCheck();
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// Add automatic unsubscribe links to the bottom of emails.
- /// http://docs.sendgrid.com/documentation/apps/subscription-tracking/
- /// </summary>
- public void EnableUnsubscribeEmail()
- {
- //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.Html = "This is the HTML body";
-
- message.Text = "This is the plain text body";
-
- //set the message subject
- message.Subject = "Hello World Unsubscribe Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //enable spamcheck
- //or optionally, you can specify 'replace' instead of the text and html in order to
- //place the link wherever you want.
- message.EnableUnsubscribe("Please click the following link to unsubscribe: <% %>", "Please click <% here %> to unsubscribe");
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// The Footer App will insert a custom footer at the bottom of the text and HTML bodies.
- /// http://docs.sendgrid.com/documentation/apps/footer/
- /// </summary>
- public void EnableFooterEmail()
- {
- //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
- var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
- message.Html = "<p style='color:red';>Hello World</p>";
- message.Html += "<p>Sent At : " + timestamp + "</p>";
-
- message.Text = "Hello World plain text";
-
- //set the message subject
- message.Subject = "Hello World Footer Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //Enable Footer
- message.EnableFooter("PLAIN TEXT FOOTER", "<p color='blue'>HTML FOOTER TEXT</p>");
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// The Footer App will insert a custom footer at the bottom of the text and HTML bodies.
- /// http://docs.sendgrid.com/documentation/apps/google-analytics/
- /// </summary>
- public void EnableGoogleAnalytics()
- {
- //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
- var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
- message.Html = "<p style='color:red';>Hello World</p>";
- message.Html += "<p>Sent At : " + timestamp + "</p>";
- message.Html += "Checkout my page at <a href=\"http://microsoft.com\">Microsoft</a>";
-
- message.Text = "Hello World plain text";
-
- //set the message subject
- message.Subject = "Hello World Footer Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //enable Google Analytics
- message.EnableGoogleAnalytics("SendGridTest", "EMAIL", "Sendgrid", "ad-one", "My SG Campaign");
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// This feature wraps an HTML template around your email content.
- /// This can be useful for sending out newsletters and/or other HTML formatted messages.
- /// http://docs.sendgrid.com/documentation/apps/email-templates/
- /// </summary>
- public void EnableTemplateEmail()
- {
- //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
- var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
- message.Html = "<p style='color:red';>Hello World</p>";
- message.Html += "<p>Sent At : " + timestamp + "</p>";
-
- message.Text = "Hello World plain text";
-
- //set the message subject
- message.Subject = "Hello World Template Test";
-
- //create an instance of the SMTP transport mechanism
- var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));
-
- //enable template
- message.EnableTemplate("<p>My Email Template <% body %> is awesome!</p>");
-
- //send the mail
- transportInstance.Deliver(message);
- }
-
- /// <summary>
- /// This feature wraps an HTML template around your email content.
- /// This can be useful for sending out newsletters and/or other HTML formatted messages.
- /// hhttp://docs.sendgrid.com/documentation/apps/email-templates/
- /// </summary>
- public void EnableBypassListManagementEmail()
- {
- //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
- var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
- message.Html = "<p style='color:red';>Hello World</p>";
- message.Html += "<p>Sent At : " + timestamp + "</p>";
-
- message.Text = "Hello World plain text";
-
- //set the message subject
- message.Subject = "Hello World Bypass List Management Test";
-
- //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 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 d3f8d4a..5b3132d 100644 --- a/SendGrid/Example/WEBAPI.cs +++ b/SendGrid/Example/WEBAPI.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Net;
using System.Net.Mail;
using SendGridMail;
-using SendGridMail.Transport;
namespace Example
{
@@ -452,7 +451,7 @@ namespace Example //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);
+ message.AddSubstitution(replacementKey, substitutionValues);
//create an instance of the SMTP transport mechanism
var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
@@ -492,7 +491,7 @@ namespace Example identifiers["customer"] = "someone";
identifiers["location"] = "somewhere";
- message.AddUniqueIdentifiers(identifiers);
+ message.AddUniqueArgs(identifiers);
//create an instance of the SMTP transport mechanism
var transportInstance = Web.GetInstance(new NetworkCredential(_username, _password));
diff --git a/SendGrid/SendGrid.sln b/SendGrid/SendGrid.sln index 61b63a3..478d898 100644 --- a/SendGrid/SendGrid.sln +++ b/SendGrid/SendGrid.sln @@ -1,14 +1,14 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail", "SendGridMail\Mail.csproj", "{3C687BEF-FF50-44AD-8315-2D4237281AF8}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{0319E73A-7039-4858-B047-1EDF88BB6BD1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.csproj", "{F39ADCE7-63B5-406D-9BE8-C407920B6B8F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{DAC6CBA4-41D4-490D-B9BE-A8E3AB2E8A96}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail", "SendGridMail\Mail.csproj", "{3C687BEF-FF50-44AD-8315-2D4237281AF8}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -19,16 +19,6 @@ Global Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|x86.ActiveCfg = Debug|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|Any CPU.Build.0 = Release|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|x86.ActiveCfg = Release|Any CPU
{0319E73A-7039-4858-B047-1EDF88BB6BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0319E73A-7039-4858-B047-1EDF88BB6BD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0319E73A-7039-4858-B047-1EDF88BB6BD1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -39,6 +29,18 @@ Global {0319E73A-7039-4858-B047-1EDF88BB6BD1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{0319E73A-7039-4858-B047-1EDF88BB6BD1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{0319E73A-7039-4858-B047-1EDF88BB6BD1}.Release|x86.ActiveCfg = Release|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Debug|x86.Build.0 = Debug|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|x86.ActiveCfg = Release|Any CPU
+ {3C687BEF-FF50-44AD-8315-2D4237281AF8}.Release|x86.Build.0 = Release|Any CPU
{F39ADCE7-63B5-406D-9BE8-C407920B6B8F}.Debug|Any CPU.ActiveCfg = Debug|x86
{F39ADCE7-63B5-406D-9BE8-C407920B6B8F}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{F39ADCE7-63B5-406D-9BE8-C407920B6B8F}.Debug|Mixed Platforms.Build.0 = Debug|x86
@@ -50,6 +52,11 @@ Global {F39ADCE7-63B5-406D-9BE8-C407920B6B8F}.Release|x86.ActiveCfg = Release|x86
{F39ADCE7-63B5-406D-9BE8-C407920B6B8F}.Release|x86.Build.0 = Release|x86
EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = Tests\Tests.csproj
+ EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
diff --git a/SendGrid/SendGridMail/Header.cs b/SendGrid/SendGridMail/Header.cs deleted file mode 100644 index e50120a..0000000 --- a/SendGrid/SendGridMail/Header.cs +++ /dev/null @@ -1,199 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Mail;
-
-namespace SendGridMail
-{
- public class Header : IHeader
- {
- private const string SendgridHeader = "X-Smtpapi";
- private readonly HeaderSettingsNode _settings;
-
- public Header()
- {
- _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 AddSection(string tag, string text)
- {
- var keys = new List<String> { "section", tag };
- _settings.AddSetting(keys, text);
- }
-
- 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)
- {
- var keys = new List<String> {"unique_args", key};
- var value = identifiers[key];
- _settings.AddSetting(keys, value);
- }
- }
-
- public void SetCategory(string category)
- {
- var keys = new List<String> {"category"};
- _settings.AddSetting(keys, category);
- }
-
- public void SetCategories(IEnumerable<string> categories)
- {
- if (categories == null) return;
- var keys = new List<String> { "category" };
- _settings.AddArray(keys, categories);
- }
-
- public void Enable(string filter)
- {
- AddFilterSetting(filter, new List<string>(){ "enable" }, "1");
- }
-
- public void Disable(string filter)
- {
- AddFilterSetting(filter, new List<string>(){"enable"}, "0");
- }
-
- public void AddFilterSetting(string filter, IEnumerable<string> settings, string value)
- {
- var keys = new List<string>() {"filters", filter, "settings" }.Concat(settings).ToList();
- _settings.AddSetting(keys, value);
- }
-
- public void AddHeader(MailMessage mime)
- {
- mime.Headers.Add(SendgridHeader, AsJson());
- }
-
- public String AsJson()
- {
- if(_settings.IsEmpty()) return "";
- return _settings.ToJson();
- }
-
- internal class HeaderSettingsNode
- {
- private readonly Dictionary<String, HeaderSettingsNode> _branches;
- private IEnumerable<String> _array;
- private String _leaf;
-
- public HeaderSettingsNode()
- {
- _branches = new Dictionary<string, HeaderSettingsNode>();
- }
-
- public void AddArray(List<String> keys, IEnumerable<String> value)
- {
- if (keys.Count == 0)
- {
- _array = value;
- }
- else
- {
- if (_leaf != null || _array != null)
- throw new ArgumentException("Attempt to overwrite setting");
-
- var key = keys.First();
- if (!_branches.ContainsKey(key))
- _branches[key] = new HeaderSettingsNode();
-
- var remainingKeys = keys.Skip(1).ToList();
- _branches[key].AddArray(remainingKeys, value);
- }
- }
-
- public void AddSetting(List<String> keys, String value)
- {
- if (keys.Count == 0)
- {
- _leaf = value;
- }
- else
- {
- if(_leaf != null || _array != null)
- throw new ArgumentException("Attempt to overwrite setting");
-
- var key = keys.First();
- if (!_branches.ContainsKey(key))
- _branches[key] = new HeaderSettingsNode();
-
- var remainingKeys = keys.Skip(1).ToList();
- _branches[key].AddSetting(remainingKeys, value);
- }
- }
-
- public String GetSetting(params String[] keys)
- {
- return GetSetting(keys.ToList());
- }
-
- public String GetSetting(List<String> keys)
- {
- if (keys.Count == 0)
- return _leaf;
- var key = keys.First();
- if(!_branches.ContainsKey(key))
- throw new ArgumentException("Bad key path!");
- var remainingKeys = keys.Skip(1).ToList();
- return _branches[key].GetSetting(remainingKeys);
- }
-
- public IEnumerable<String> GetArray(params String[] keys)
- {
- return GetArray(keys.ToList());
- }
-
- public IEnumerable<String> GetArray(List<String> keys)
- {
- if (keys.Count == 0)
- return _array;
- var key = keys.First();
- if (!_branches.ContainsKey(key))
- throw new ArgumentException("Bad key path!");
- var remainingKeys = keys.Skip(1).ToList();
- return _branches[key].GetArray(remainingKeys);
- }
-
- public String GetLeaf()
- {
- return _leaf;
- }
-
- public String ToJson()
- {
- if (_branches.Count > 0)
- return "{" + String.Join(",", _branches.Keys.Select(k => Utils.Serialize(k) + " : " + _branches[k].ToJson())) + "}";
- if (_leaf != null)
- return Utils.Serialize(_leaf);
- if (_array != null)
- return "[" + String.Join(", ", _array.Select(i => Utils.Serialize(i))) + "]";
- return "{}";
- }
-
- public bool IsEmpty()
- {
- if (_leaf != null) return false;
- return _branches == null || _branches.Keys.Count == 0;
- }
- }
- }
-}
diff --git a/SendGrid/SendGridMail/IHeader.cs b/SendGrid/SendGridMail/IHeader.cs deleted file mode 100644 index 610de72..0000000 --- a/SendGrid/SendGridMail/IHeader.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Mail;
-using System.Text;
-
-namespace SendGridMail
-{
- /// <summary>
- /// Represents the additional functionality to add SendGrid specific mail headers
- /// </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.
- /// </summary>
- /// <param name="tag">string to be replaced in the message</param>
- /// <param name="substitutions">substitutions to be made, one per recipient</param>
- void AddSubVal(String tag, IEnumerable<String> substitutions);
-
- /// <summary>
- /// Adds a substitution section to be used during the mail merge.
- /// </summary>
- /// <param name="tag">string to be replaced with the section in the message</param>
- /// <param name="text">The text of the section. May include substituion tags.</param>
- void AddSection(String tag, String text);
-
- /// <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>
- /// <param name="identifiers">parameter value pairs to be passed back on event notification</param>
- void AddUniqueIdentifier(IDictionary<String, String> identifiers);
-
- /// <summary>
- /// 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.
- /// </summary>
- /// <param name="category">categories applied to the message</param>
- void SetCategory(String category);
-
- /// <summary>
- /// This sets the categories for this email. Statistics are stored on a per category
- /// basis, so this can be useful for tracking on a per group basis.
- /// </summary>
- /// <param name="categories">categories applied to the message</param>
- void SetCategories(IEnumerable<string> categories);
-
- /// <summary>
- /// Shortcut method for enabling a filter.
- /// </summary>
- /// <param name="filter">The name of the filter to enable</param>
- void Enable(String filter);
-
- /// <summary>
- /// Shortcut method for disabling a filter.
- /// </summary>
- /// <param name="filter">The name of the filter to disable</param>
- void Disable(String filter);
-
- /// <summary>
- /// Allows you to specify a filter setting. You can find a list of filters and settings here:
- /// http://docs.sendgrid.com/documentation/api/web-api/filtersettings/
- /// </summary>
- /// <param name="filter">The name of the filter to set</param>
- /// <param name="settings">The multipart name of the parameter being set</param>
- /// <param name="value">The value that the settings name will be assigning</param>
- void AddFilterSetting(String filter, IEnumerable<String> settings, String value);
-
- /// <summary>
- /// Attaches the SendGrid headers to the MIME.
- /// </summary>
- /// <param name="mime">the MIME to which we are attaching</param>
- void AddHeader(MailMessage mime);
-
- /// <summary>
- /// Converts the filter settings into a JSON string.
- /// </summary>
- /// <returns>String representation of the SendGrid headers</returns>
- String AsJson();
- }
-}
diff --git a/SendGrid/SendGridMail/ISendGrid.cs b/SendGrid/SendGridMail/ISendGrid.cs index 9725be0..ad868eb 100755..100644 --- a/SendGrid/SendGridMail/ISendGrid.cs +++ b/SendGrid/SendGridMail/ISendGrid.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO;
using System.Net;
using System.Net.Mail;
+using Smtpapi;
namespace SendGridMail
{
@@ -99,14 +100,14 @@ namespace SendGridMail /// </summary>
/// <param name="replacementTag">the string in the email that you'll replace eg. '-name-'</param>
/// <param name="substitutionValues">a list of values that will be substituted in for the replacementTag, one for each recipient</param>
- void AddSubVal(String replacementTag, List<String> substitutionValues);
+ void AddSubstitution(String replacementTag, List<String> substitutionValues);
/// <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>
/// <param name="identifiers">parameter substitutionValues pairs to be passed back on event notification</param>
- void AddUniqueIdentifiers(IDictionary<String, String> identifiers);
+ void AddUniqueArgs(IDictionary<String, String> identifiers);
/// <summary>
/// This sets the category for this email. Statistics are stored on a per category
diff --git a/SendGrid/SendGridMail/Mail.csproj b/SendGrid/SendGridMail/Mail.csproj index 28a906f..a41ecbe 100644 --- a/SendGrid/SendGridMail/Mail.csproj +++ b/SendGrid/SendGridMail/Mail.csproj @@ -43,6 +43,9 @@ <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
+ <Reference Include="Smtpapi">
+ <HintPath>..\packages\smtpapi.1.0.0\lib\Smtpapi.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
@@ -64,15 +67,11 @@ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="Header.cs" />
- <Compile Include="IHeader.cs" />
<Compile Include="ISendGrid.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SendGrid.cs" />
<Compile Include="Transport\ITransport.cs" />
<Compile Include="Transport\Web.cs" />
- <Compile Include="Transport\SMTP.cs" />
- <Compile Include="Utils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs index 44225db..f551328 100644 --- a/SendGrid/SendGridMail/SendGrid.cs +++ b/SendGrid/SendGridMail/SendGrid.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Net;
using System.Net.Mail;
using System.Net.Mime;
-using SendGridMail.Transport;
+using Smtpapi;
namespace SendGridMail
{
@@ -290,15 +290,15 @@ namespace SendGridMail set { _attachments = value.ToList(); }
}
- public void AddSubVal(String replacementTag, List<String> substitutionValues)
+ public void AddSubstitution(String replacementTag, List<String> substitutionValues)
{
//let the system complain if they do something bad, since the function returns null
- Header.AddSubVal(replacementTag, substitutionValues);
+ Header.AddSubstitution(replacementTag, substitutionValues);
}
- public void AddUniqueIdentifiers(IDictionary<String, String> identifiers)
+ public void AddUniqueArgs(IDictionary<String, String> identifiers)
{
- Header.AddUniqueIdentifier(identifiers);
+ Header.AddUniqueArgs(identifiers);
}
public void SetCategory(String category)
@@ -343,69 +343,69 @@ namespace SendGridMail #region SMTP API Functions
public void DisableGravatar()
{
- Header.Disable(Filters["Gravatar"]);
+ Header.DisableFilter(Filters["Gravatar"]);
}
public void DisableOpenTracking()
{
- Header.Disable(Filters["OpenTracking"]);
+ Header.DisableFilter(Filters["OpenTracking"]);
}
public void DisableClickTracking()
{
- Header.Disable(Filters["ClickTracking"]);
+ Header.DisableFilter(Filters["ClickTracking"]);
}
public void DisableSpamCheck()
{
- Header.Disable(Filters["SpamCheck"]);
+ Header.DisableFilter(Filters["SpamCheck"]);
}
public void DisableUnsubscribe()
{
- Header.Disable(Filters["Unsubscribe"]);
+ Header.DisableFilter(Filters["Unsubscribe"]);
}
public void DisableFooter()
{
- Header.Disable(Filters["Footer"]);
+ Header.DisableFilter(Filters["Footer"]);
}
public void DisableGoogleAnalytics()
{
- Header.Disable(Filters["GoogleAnalytics"]);
+ Header.DisableFilter(Filters["GoogleAnalytics"]);
}
public void DisableTemplate()
{
- Header.Disable(Filters["Template"]);
+ Header.DisableFilter(Filters["Template"]);
}
public void DisableBcc()
{
- Header.Disable(Filters["Bcc"]);
+ Header.DisableFilter(Filters["Bcc"]);
}
public void DisableBypassListManagement()
{
- Header.Disable(Filters["BypassListManagement"]);
+ Header.DisableFilter(Filters["BypassListManagement"]);
}
public void EnableGravatar()
{
- Header.Enable(Filters["Gravatar"]);
+ Header.EnableFilter(Filters["Gravatar"]);
}
public void EnableOpenTracking()
{
- Header.Enable(Filters["OpenTracking"]);
+ Header.EnableFilter(Filters["OpenTracking"]);
}
public void EnableClickTracking(bool includePlainText = false)
{
var filter = Filters["ClickTracking"];
- Header.Enable(filter);
+ Header.EnableFilter(filter);
if (includePlainText)
{
Header.AddFilterSetting(filter, new List<string> { "enable_text" }, "1");
@@ -416,7 +416,7 @@ namespace SendGridMail {
var filter = Filters["SpamCheck"];
- Header.Enable(filter);
+ Header.EnableFilter(filter);
Header.AddFilterSetting(filter, new List<string> { "maxscore" }, score.ToString(CultureInfo.InvariantCulture));
Header.AddFilterSetting(filter, new List<string> { "url" }, url);
}
@@ -435,7 +435,7 @@ namespace SendGridMail throw new Exception("Missing substitution replacementTag in html");
}
- Header.Enable(filter);
+ Header.EnableFilter(filter);
Header.AddFilterSetting(filter, new List<string> { "text/plain" }, text);
Header.AddFilterSetting(filter, new List<string> {"text/html"}, html);
}
@@ -444,7 +444,7 @@ namespace SendGridMail {
var filter = Filters["Unsubscribe"];
- Header.Enable(filter);
+ Header.EnableFilter(filter);
Header.AddFilterSetting(filter, new List<string> { "replace" }, replace);
}
@@ -452,7 +452,7 @@ namespace SendGridMail {
var filter = Filters["Footer"];
- Header.Enable(filter);
+ Header.EnableFilter(filter);
Header.AddFilterSetting(filter, new List<string> { "text/plain" }, text);
Header.AddFilterSetting(filter, new List<string> { "text/html" }, html);
}
@@ -461,7 +461,7 @@ namespace SendGridMail {
var filter = Filters["GoogleAnalytics"];
- Header.Enable(filter);
+ Header.EnableFilter(filter);
Header.AddFilterSetting(filter, new List<string> { "utm_source" }, source);
Header.AddFilterSetting(filter, new List<string> { "utm_medium" }, medium);
Header.AddFilterSetting(filter, new List<string> { "utm_term" }, term);
@@ -478,7 +478,7 @@ namespace SendGridMail throw new Exception("Missing substitution replacementTag in html");
}
- Header.Enable(filter);
+ Header.EnableFilter(filter);
Header.AddFilterSetting(filter, new List<string> { "text/html" }, html);
}
@@ -486,19 +486,19 @@ namespace SendGridMail {
var filter = Filters["Bcc"];
- Header.Enable(filter);
+ Header.EnableFilter(filter);
Header.AddFilterSetting(filter, new List<string> { "email" }, email);
}
public void EnableBypassListManagement()
{
- Header.Enable(Filters["BypassListManagement"]);
+ Header.EnableFilter(Filters["BypassListManagement"]);
}
#endregion
public MailMessage CreateMimeMessage()
{
- String smtpapi = Header.AsJson();
+ String smtpapi = Header.JsonString();
if (!String.IsNullOrEmpty(smtpapi))
message.Headers.Add("X-Smtpapi", smtpapi);
diff --git a/SendGrid/SendGridMail/Transport/ITransport.cs b/SendGrid/SendGridMail/Transport/ITransport.cs index b3a1936..0394cec 100755..100644 --- a/SendGrid/SendGridMail/Transport/ITransport.cs +++ b/SendGrid/SendGridMail/Transport/ITransport.cs @@ -1,4 +1,4 @@ -namespace SendGridMail.Transport
+namespace SendGridMail
{
/// <summary>
/// Encapsulates the transport mechanism so that it can be used in a generic way,
diff --git a/SendGrid/SendGridMail/Transport/SMTP.cs b/SendGrid/SendGridMail/Transport/SMTP.cs deleted file mode 100755 index a878ce8..0000000 --- a/SendGrid/SendGridMail/Transport/SMTP.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System;
-using System.Net;
-using System.Net.Mail;
-
-namespace SendGridMail.Transport
-{
- /// <summary>
- /// Transport class for delivering messages via SMTP
- /// </summary>
- public class SMTP : ITransport
- {
- /// <summary>
- /// SendGrid's host name
- /// </summary>
- public const String SmtpServer = "smtp.sendgrid.net";
-
- /// <summary>
- /// Port for Simple Mail Transfer Protocol
- /// </summary>
- public const Int32 Port = 25;
-
- /// <summary>
- /// Port for Secure SMTP
- /// </summary>
- public const Int32 SslPort = 465;
-
- /// <summary>
- /// Port for TLS (currently not supported)
- /// </summary>
- public const Int32 TlsPort = 571;
-
- /// <summary>
- /// Client used to deliver SMTP message
- /// </summary>
- private readonly ISmtpClient _client;
-
- /// <summary>
- /// Transport created to deliver messages to SendGrid using SMTP
- /// </summary>
- /// <param name="client">SMTP client we are wrapping</param>
- /// <param name="credentials">Sendgrid user credentials</param>
- /// <param name="host">MTA recieving this message. By default, sent through SendGrid.</param>
- /// <param name="port">SMTP port 25 is the default. Port 465 can be used for Secure SMTP.</param>
- private SMTP(ISmtpClient client, NetworkCredential credentials, string host = SmtpServer, int port = Port)
- {
- _client = client;
- switch (port)
- {
- case Port:
- break;
- case SslPort:
- _client.EnableSsl = true;
- break;
- case TlsPort:
- throw new NotSupportedException("TLS not supported");
- }
- }
-
- /// <summary>
- /// Deliver an email using SMTP protocol
- /// </summary>
- /// <param name="message"></param>
- public void Deliver(ISendGrid message)
- {
- var mime = message.CreateMimeMessage();
- _client.Send(mime);
- }
-
- /// <summary>
- /// Transport created to deliver messages to SendGrid using SMTP
- /// </summary>
- /// <param name="credentials">Sendgrid user credentials</param>
- /// <param name="host">MTA recieving this message. By default, sent through SendGrid.</param>
- /// <param name="port">SMTP port 25 is the default. Port 465 can be used for Secure SMTP.</param>
- public static SMTP GetInstance(NetworkCredential credentials, String host = SmtpServer, Int32 port = Port)
- {
- var client = new SmtpWrapper(host, port, credentials, SmtpDeliveryMethod.Network);
- return new SMTP(client, credentials, host, port);
- }
-
- /// <summary>
- /// For Unit Testing Only!
- /// </summary>
- /// <param name="client"></param>
- /// <param name="credentials"></param>
- /// <param name="host"></param>
- /// <param name="port"></param>
- /// <returns></returns>
- internal static SMTP GetInstance(ISmtpClient client, NetworkCredential credentials, String host = SmtpServer, Int32 port = Port)
- {
- return new SMTP(client, credentials, host, port);
- }
-
- /// <summary>
- /// Interface to allow testing
- /// </summary>
- internal interface ISmtpClient
- {
- bool EnableSsl { get; set; }
- void Send(MailMessage mime);
- }
-
- /// <summary>
- /// Implementation of SmtpClient wrapper, separated to allow dependency injection
- /// </summary>
- internal class SmtpWrapper : ISmtpClient
- {
- private readonly SmtpClient _client;
- public bool EnableSsl
- {
- get
- {
- return _client.EnableSsl;
- }
- set
- {
- _client.EnableSsl = value;
- }
- }
-
- public SmtpWrapper(String host, Int32 port, NetworkCredential credentials, SmtpDeliveryMethod deliveryMethod)
- {
- _client = new SmtpClient(host, port) { Credentials = credentials, DeliveryMethod = deliveryMethod };
- }
-
- public void Send(MailMessage mime)
- {
- _client.Send(mime);
- }
- }
- }
-}
diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs index 0909e34..c99dcf7 100644 --- a/SendGrid/SendGridMail/Transport/Web.cs +++ b/SendGrid/SendGridMail/Transport/Web.cs @@ -7,8 +7,9 @@ using System.Net.Http.Headers; using System.Xml;
using System.Net.Http;
using System.Threading.Tasks;
+using Smtpapi;
-namespace SendGridMail.Transport
+namespace SendGridMail
{
public class Web : ITransport
{
@@ -189,7 +190,7 @@ namespace SendGridMail.Transport new KeyValuePair<String, String>("subject", message.Subject),
new KeyValuePair<String, String>("text", message.Text),
new KeyValuePair<String, String>("html", message.Html),
- new KeyValuePair<String, String>("x-smtpapi", message.Header.AsJson())
+ new KeyValuePair<String, String>("x-smtpapi", message.Header.JsonString())
};
if(message.To != null)
{
diff --git a/SendGrid/SendGridMail/Utils.cs b/SendGrid/SendGridMail/Utils.cs deleted file mode 100755 index 0221aa4..0000000 --- a/SendGrid/SendGridMail/Utils.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.IO;
-using System.IO.Pipes;
-using System.Linq;
-using System.Net;
-using System.Net.Mail;
-using System.Runtime.Serialization.Json;
-using System.Text;
-
-namespace SendGridMail
-{
- public class Utils
- {
- public static string Serialize<T>(T obj)
- {
- var serializer = new DataContractJsonSerializer(obj.GetType());
- using (var stream = new MemoryStream())
- {
- serializer.WriteObject(stream, obj);
- var jsonData = Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Length);
- return jsonData;
- }
- }
-
- public static string SerializeDictionary(IDictionary<String, String> dic)
- {
- return "{"+String.Join(",",dic.Select(kvp => Serialize(kvp.Key) + ":" + Serialize(kvp.Value)))+"}";
- }
- }
-}
diff --git a/SendGrid/SendGridMail/packages.config b/SendGrid/SendGridMail/packages.config index f1c67e3..aa0484c 100644 --- a/SendGrid/SendGridMail/packages.config +++ b/SendGrid/SendGridMail/packages.config @@ -4,4 +4,5 @@ <package id="Microsoft.Bcl.Async" version="1.0.16" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
+ <package id="smtpapi" version="1.0.0" targetFramework="net40" />
</packages>
\ No newline at end of file diff --git a/SendGrid/Tests/TestHeader.cs b/SendGrid/Tests/TestHeader.cs deleted file mode 100644 index c93f1fc..0000000 --- a/SendGrid/Tests/TestHeader.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Mail;
-using System.Text;
-using Moq;
-using NUnit.Framework;
-using SendGridMail;
-
-namespace Tests
-{
- [TestFixture]
- public class TestHeader
- {
- [Test]
- public void TestAddSubVal()
- {
- var test = new Header();
- test.AddSubVal("foo", new List<string>{"bar", "raz"});
- var result = test.AsJson();
- Assert.AreEqual("{\"sub\" : {\"foo\" : [\"bar\", \"raz\"]}}", result);
- }
-
- [Test]
- public void TestAddSection()
- {
- var test = new Header();
- test.AddSection("foo", "bar");
- var result = test.AsJson();
- Assert.AreEqual("{\"section\" : {\"foo\" : \"bar\"}}", result);
- }
-
- [Test]
- public void TestAddUniqueIdentifier()
- {
- var test = new Header();
- test.AddUniqueIdentifier(new Dictionary<string, string>(){{"foo", "bar"}});
- var result = test.AsJson();
- Assert.AreEqual("{\"unique_args\" : {\"foo\" : \"bar\"}}", result);
- }
-
- [Test]
- public void TestSetCategory()
- {
- var test = new Header();
- test.SetCategory("foo");
- var result = test.AsJson();
- Assert.AreEqual("{\"category\" : \"foo\"}", result);
- }
-
- [Test]
- public void TestSetCategories()
- {
- var test = new Header();
- test.SetCategories(new List<string>{"dogs","animals","pets","mammals"});
- var result = test.AsJson();
- Assert.AreEqual("{\"category\" : [\"dogs\", \"animals\", \"pets\", \"mammals\"]}", result);
- }
-
- [Test]
- public void TestEnable()
- {
- var test = new Header();
- test.Enable("foo");
- var result = test.AsJson();
- Assert.AreEqual("{\"filters\" : {\"foo\" : {\"settings\" : {\"enable\" : \"1\"}}}}", result);
- }
-
- [Test]
- public void TestDisable()
- {
- var test = new Header();
- test.Disable("foo");
- var result = test.AsJson();
- Assert.AreEqual("{\"filters\" : {\"foo\" : {\"settings\" : {\"enable\" : \"0\"}}}}", result);
- }
-
- [Test]
- public void TestAddFilterSetting()
- {
- var test = new Header();
- test.AddFilterSetting("foo", new List<string> { "a", "b" }, "bar");
- var result = test.AsJson();
- Assert.AreEqual("{\"filters\" : {\"foo\" : {\"settings\" : {\"a\" : {\"b\" : \"bar\"}}}}}", result);
-
- }
-
- [Test]
- public void TestAddHeader()
- {
- var test = new Header();
- test.AddSubVal("foo", new List<string> { "a", "b" });
- var mime = new MailMessage();
- test.AddHeader(mime);
- var result = mime.Headers.Get("x-smtpapi");
- Assert.AreEqual("{\"sub\" : {\"foo\" : [\"a\", \"b\"]}}", result);
- }
-
- [Test]
- public void TestAsJson()
- {
- var test = new Header();
- var result = test.AsJson();
- Assert.AreEqual("", result);
-
- test = new Header();
- test.AddSubVal("foo", new List<string>{"a", "b"});
- result = test.AsJson();
- Assert.AreEqual("{\"sub\" : {\"foo\" : [\"a\", \"b\"]}}", result);
- }
- }
-}
diff --git a/SendGrid/Tests/TestJsonUtils.cs b/SendGrid/Tests/TestJsonUtils.cs deleted file mode 100755 index fee990d..0000000 --- a/SendGrid/Tests/TestJsonUtils.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text;
-using NUnit.Framework;
-using SendGridMail;
-
-namespace Tests
-{
- [TestFixture]
- public class TestJsonUtils
- {
- [Test]
- public void TestSerialize()
- {
- Assert.AreEqual("1", Utils.Serialize(1));
- Assert.AreEqual("\"\\\"foo\\\"\"", Utils.Serialize("\"foo\""));
- }
- }
-}
diff --git a/SendGrid/Tests/TestSendgrid.cs b/SendGrid/Tests/TestSendgrid.cs index 95604d3..a005f86 100755..100644 --- a/SendGrid/Tests/TestSendgrid.cs +++ b/SendGrid/Tests/TestSendgrid.cs @@ -7,6 +7,7 @@ using System.Net.Mail; using System.Text;
using NUnit.Framework;
using SendGridMail;
+using Smtpapi;
namespace Tests
{
@@ -21,7 +22,7 @@ namespace Tests sendgrid.DisableGravatar();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"gravatar\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -33,7 +34,7 @@ namespace Tests sendgrid.DisableOpenTracking();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"opentrack\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -45,7 +46,7 @@ namespace Tests sendgrid.DisableClickTracking();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"clicktrack\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -57,7 +58,7 @@ namespace Tests sendgrid.DisableSpamCheck();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"spamcheck\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -69,7 +70,7 @@ namespace Tests sendgrid.DisableUnsubscribe();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"subscriptiontrack\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -81,7 +82,7 @@ namespace Tests sendgrid.DisableFooter();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"footer\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -93,7 +94,7 @@ namespace Tests sendgrid.DisableGoogleAnalytics();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"ganalytics\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -105,7 +106,7 @@ namespace Tests sendgrid.DisableTemplate();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"template\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -117,7 +118,7 @@ namespace Tests sendgrid.DisableBcc();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"bcc\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -129,7 +130,7 @@ namespace Tests sendgrid.DisableBypassListManagement();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"bypass_list_management\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
}
@@ -141,7 +142,7 @@ namespace Tests sendgrid.EnableGravatar();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"gravatar\" : {\"settings\" : {\"enable\" : \"1\"}}}}", json);
}
@@ -153,7 +154,7 @@ namespace Tests sendgrid.EnableOpenTracking();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"opentrack\" : {\"settings\" : {\"enable\" : \"1\"}}}}", json);
}
@@ -165,7 +166,7 @@ namespace Tests bool includePlainText = true;
sendgrid.EnableClickTracking(includePlainText);
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"clicktrack\" : {\"settings\" : {\"enable\" : \"1\",\"enable_text\" : \"1\"}}}}", json);
}
@@ -179,7 +180,7 @@ namespace Tests var url = "http://www.example.com";
sendgrid.EnableSpamCheck(score, url);
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"spamcheck\" : {\"settings\" : {\"enable\" : \"1\",\"maxscore\" : \"5\",\"url\" : \"http:\\/\\/www.example.com\"}}}}", json);
}
@@ -197,7 +198,7 @@ namespace Tests sendgrid.EnableUnsubscribe(text, html);
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"subscriptiontrack\" : {\"settings\" : {\"enable\" : \"1\","+
jsonText+","+jsonHtml+"}}}}", json);
@@ -209,7 +210,7 @@ namespace Tests sendgrid.EnableUnsubscribe(replace);
- json = header.AsJson();
+ json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"subscriptiontrack\" : {\"settings\" : {\"enable\" : \"1\"," + jsonReplace + "}}}}", json);
text = "bad";
@@ -234,7 +235,7 @@ namespace Tests sendgrid.EnableFooter(text, html);
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"footer\" : {\"settings\" : {\"enable\" : \"1\",\"text\\/plain\" : \""+text+"\",\"text\\/html\" : \""+escHtml+"\"}}}}", json);
}
@@ -258,7 +259,7 @@ namespace Tests var jsonContent = "\"utm_content\" : \"" + content + "\"";
var jsonCampaign = "\"utm_campaign\" : \"" + campaign + "\"";
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"ganalytics\" : {\"settings\" : {\"enable\" : \"1\","+
jsonSource+","+jsonMedium+","+jsonTerm+","+jsonContent+","+jsonCampaign+"}}}}", json);
}
@@ -273,7 +274,7 @@ namespace Tests var escHtml = "<% hadhdhd %>";
sendgrid.EnableTemplate(html);
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"template\" : {\"settings\" : {\"enable\" : \"1\",\"text\\/html\" : \""+escHtml+"\"}}}}", json);
escHtml = "bad";
@@ -289,7 +290,7 @@ namespace Tests var email = "somebody@someplace.com";
sendgrid.EnableBcc(email);
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"bcc\" : {\"settings\" : {\"enable\" : \"1\",\"email\" : \"" + email + "\"}}}}", json);
}
@@ -301,7 +302,7 @@ namespace Tests sendgrid.EnableBypassListManagement();
- String json = header.AsJson();
+ String json = header.JsonString();
Assert.AreEqual("{\"filters\" : {\"bypass_list_management\" : {\"settings\" : {\"enable\" : \"1\"}}}}", json);
}
diff --git a/SendGrid/Tests/TestSendgridMessageSetup.cs b/SendGrid/Tests/TestSendgridMessageSetup.cs deleted file mode 100755 index 5719d04..0000000 --- a/SendGrid/Tests/TestSendgridMessageSetup.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Mail;
-using System.Net.Mime;
-using Moq;
-using NUnit.Framework;
-using SendGridMail;
-
-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()
- {
- var foo = new Mock<IHeader>();
-
- var sg = new SendGrid(foo.Object);
- sg.AddTo("eric@sendgrid.com");
- Assert.AreEqual("eric@sendgrid.com", sg.To.First().ToString(), "Single To Address" );
-
- sg = new SendGrid(foo.Object);
- var strings = new String[2];
- strings[0] = "eric@sendgrid.com";
- strings[1] = "tyler@sendgrid.com";
- sg.AddTo(strings);
- Assert.AreEqual("eric@sendgrid.com", sg.To[0].ToString(), "Multiple To addresses, check first one");
- Assert.AreEqual("tyler@sendgrid.com", sg.To[1].ToString(), "Multiple To addresses, check second one");
-
- sg = new SendGrid(foo.Object);
- var a = new Dictionary<String, String>();
- a.Add("DisplayName", "Eric");
- var datastruct = new Dictionary<string, IDictionary<string, string>> {{"eric@sendgrid.com", a}};
- sg.AddTo(datastruct);
- Assert.AreEqual("Eric", sg.To.First().DisplayName, "Single address with args");
- }
-
- [Test]
- public void TestAddCc()
- {
- var foo = new Mock<IHeader>();
-
- var sg = new SendGrid(foo.Object);
- sg.AddCc("eric@sendgrid.com");
- Assert.AreEqual("eric@sendgrid.com", sg.Cc.First().ToString(), "Single CC Address");
-
- sg = new SendGrid(foo.Object);
- var strings = new String[2];
- strings[0] = "eric@sendgrid.com";
- strings[1] = "tyler@sendgrid.com";
- sg.AddCc(strings);
- Assert.AreEqual("eric@sendgrid.com", sg.Cc[0].ToString(), "Multiple CC addresses, check first one");
- Assert.AreEqual("tyler@sendgrid.com", sg.Cc[1].ToString(), "Multiple CC addresses, check second one");
-
- sg = new SendGrid(foo.Object);
- var a = new Dictionary<String, String>();
- a.Add("DisplayName", "Eric");
- var datastruct = new Dictionary<string, IDictionary<string, string>> { { "eric@sendgrid.com", a } };
- sg.AddCc(datastruct);
- Assert.AreEqual("Eric", sg.Cc.First().DisplayName, "Single CC address with args");
- }
-
- [Test]
- public void TestAddBcc()
- {
- var foo = new Mock<IHeader>();
-
- var sg = new SendGrid(foo.Object);
- sg.AddBcc("eric@sendgrid.com");
- Assert.AreEqual("eric@sendgrid.com", sg.Bcc.First().ToString(), "Single Bcc Address");
-
- sg = new SendGrid(foo.Object);
- var strings = new String[2];
- strings[0] = "eric@sendgrid.com";
- strings[1] = "tyler@sendgrid.com";
- sg.AddBcc(strings);
- Assert.AreEqual("eric@sendgrid.com", sg.Bcc[0].ToString(), "Multiple addresses, check first one");
- Assert.AreEqual("tyler@sendgrid.com", sg.Bcc[1].ToString(), "Multiple addresses, check second one");
-
- sg = new SendGrid(foo.Object);
- var a = new Dictionary<String, String>();
- a.Add("DisplayName", "Eric");
- var datastruct = new Dictionary<string, IDictionary<string, string>> { { "eric@sendgrid.com", a } };
- sg.AddBcc(datastruct);
- Assert.AreEqual("Eric", sg.Bcc.First().DisplayName, "Single address with args");
- }
-
- [Test]
- public void TestSGHeader()
- {
- var foo = new Mock<IHeader>();
- var sg = new SendGrid(foo.Object);
-
- sg.Subject = "New Test Subject";
- Assert.AreEqual("New Test Subject", sg.Subject, "Subject set ok");
- sg.Subject = null;
- Assert.AreEqual("New Test Subject", sg.Subject, "null subject does not overide previous subject");
- }
-
- [Test]
- public void TestAddSubVal()
- {
- var substitutionStrings = new List<String> {"foo", "bar", "beer"};
- var mock = new Mock<IHeader>();
-
- var sg = new SendGrid(mock.Object);
- sg.AddSubVal("-name-", substitutionStrings);
-
- mock.Verify(foo => foo.AddSubVal("-name-", substitutionStrings));
- }
-
- [Test]
- public void TestAddUniqueIdentifier()
- {
-
- var kvp = new Dictionary<String, String> { {"foo", "bar"}, {"beer", "good"} };
- var mock = new Mock<IHeader>();
-
- var sg = new SendGrid(mock.Object);
- sg.AddUniqueIdentifiers(kvp);
-
- mock.Verify(foo => foo.AddUniqueIdentifier(kvp));
- }
-
- [Test]
- public void TestSetCategory()
- {
- var cat = "foo";
- var mock = new Mock<IHeader>();
-
- var sg = new SendGrid(mock.Object);
- sg.SetCategory(cat);
-
- mock.Verify(foo => foo.SetCategory(cat));
- }
-
- [Test]
- public void TestGetRcpts()
- {
- var foo = new Mock<IHeader>();
- var sg = new SendGrid(foo.Object);
-
- sg.AddTo("eric@sendgrid.com");
- sg.AddCc("tyler@sendgrid.com");
- sg.AddBcc("cj@sendgrid.com");
- sg.AddBcc("foo@sendgrid.com");
-
- var rcpts = sg.GetRecipients();
- Assert.AreEqual("eric@sendgrid.com", rcpts.First(), "getRecipients check To");
- Assert.AreEqual("tyler@sendgrid.com", rcpts.Skip(1).First(), "getRecipients check Cc");
- Assert.AreEqual("cj@sendgrid.com", rcpts.Skip(2).First(), "getRecipients check Bcc");
- Assert.AreEqual("foo@sendgrid.com", rcpts.Skip(3).First(), "getRecipients check Bcc x2");
- }
-
- [Test]
- public void TestAddAttachment()
- {
- var foo = new Mock<IHeader>();
- var sg = new SendGrid(foo.Object);
-
- sg.AddAttachment("pnunit.framework.dll");
- sg.AddAttachment("pnunit.framework.dll");
- //Assert.AreEqual(data.ContentStream, sg.Attachments.First().ContentStream, "Attach via path");
- //Assert.AreEqual(data.ContentStream, sg.Attachments.Skip(1).First().ContentStream, "Attach via path x2");
-
- sg = new SendGrid(foo.Object);
- //sg.AddAttachment(data);
- //sg.AddAttachment(data);
- //Assert.AreEqual(data.ContentStream, sg.Attachments.First().ContentStream, "Attach via attachment");
- //Assert.AreEqual(data.ContentStream, sg.Attachments.Skip(1).First().ContentStream, "Attach via attachment x2");
-
- sg = new SendGrid(foo.Object);
- //sg.AddAttachment(data.ContentStream, data.ContentType);
- //sg.AddAttachment(data.ContentStream, data.ContentType);
- //Assert.AreEqual(data.ContentStream, sg.Attachments.First().ContentStream, "Attach via stream");
- //Assert.AreEqual(data.ContentStream, sg.Attachments.Skip(1).First().ContentStream, "Attach via stream x2");
- }
- }
-}
diff --git a/SendGrid/Tests/TestTreeNode.cs b/SendGrid/Tests/TestTreeNode.cs deleted file mode 100755 index 1701d74..0000000 --- a/SendGrid/Tests/TestTreeNode.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using NUnit.Framework;
-using SendGridMail;
-
-namespace Tests
-{
- [TestFixture]
- public class TestTreeNode
- {
- [Test]
- public void TestAddSetting()
- {
- var test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string>(), "foo");
- Assert.AreEqual("foo", test.GetLeaf(), "Get the leaf of the first node");
-
- test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string> { "foo" }, "bar");
- Assert.AreEqual("bar", test.GetSetting(new List<string>(){"foo"}), "Get the item in the first branch 'foo', make sure its set to 'bar'");
-
- test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string> {"foo"}, "bar");
- Assert.AreEqual("bar", test.GetSetting("foo"), "tests the convienence get setting function that omits the lists stuff...");
-
- test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string> { "foo", "bar", "raz" }, "foobar");
- Assert.AreEqual("foobar", test.GetSetting("foo", "bar", "raz"), "tests a tree that is multiple branches deep");
-
- test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string> { "foo", "bar", "raz" }, "foobar");
- test.AddSetting(new List<string> { "barfoo", "barbar", "barraz" }, "barfoobar");
- Assert.AreEqual("foobar", test.GetSetting("foo", "bar", "raz"), "tests a tree that has multiple branches");
- Assert.AreEqual("barfoobar", test.GetSetting("barfoo", "barbar", "barraz"), "tests the other branch");
-
- test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string> { "foo" }, "bar");
- try
- {
- test.AddSetting(new List<string> {"foo", "raz"}, "blam");
- Assert.Fail("exception not thrown");
- }
- catch (ArgumentException ex)
- {
- Assert.AreEqual("Attempt to overwrite setting", ex.Message);
- }
-
- }
-
- [Test]
- public void TestToJSON()
- {
- var test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string>() { "foo", "bar", "raz" }, "foobar");
-
- var result = test.ToJson();
- Assert.AreEqual("{\"foo\" : {\"bar\" : {\"raz\" : \"foobar\"}}}", result);
-
- test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string>() { "foo", "bar", "raz" }, "foobar");
- test.AddSetting(new List<string>() { "barfoo", "barbar", "barraz" }, "barfoobar");
-
- result = test.ToJson();
- Assert.AreEqual("{\"foo\" : {\"bar\" : {\"raz\" : \"foobar\"}},\"barfoo\" : {\"barbar\" : {\"barraz\" : \"barfoobar\"}}}", result);
-
- test = new Header.HeaderSettingsNode();
- test.AddArray(new List<string>{"foo"}, new List<string>{"bar", "raz"});
- result = test.ToJson();
- Assert.AreEqual("{\"foo\" : [\"bar\", \"raz\"]}", result);
-
- }
-
- [Test]
- public void TestAddArray()
- {
- var test = new Header.HeaderSettingsNode();
- test.AddArray(new List<string>{"foo", "bar"}, new string[]{"raz", "blam"});
- var result = test.GetArray("foo", "bar");
- Assert.AreEqual(result.ToList()[0], "raz");
- Assert.AreEqual(result.ToList()[1], "blam");
- }
-
- [Test]
- public void TestIsEmpty()
- {
- var test = new Header.HeaderSettingsNode();
- Assert.IsTrue(test.IsEmpty());
-
- test = new Header.HeaderSettingsNode();
- test.AddSetting(new List<string>{"foo"}, "bar");
- Assert.IsFalse(test.IsEmpty());
-
- test = new Header.HeaderSettingsNode();
- test.AddArray(new List<string> { "raz" }, new List<string>{"blam"});
- Assert.IsFalse(test.IsEmpty());
-
- }
- }
-}
diff --git a/SendGrid/Tests/TestUtils.cs b/SendGrid/Tests/TestUtils.cs deleted file mode 100755 index 48febcf..0000000 --- a/SendGrid/Tests/TestUtils.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
-using SendGridMail;
-
-namespace Tests
-{
- [TestFixture]
- public class TestUtils
- {
- [Test]
- public void TestSerialize()
- {
- var testcase = "foo";
- String result = Utils.Serialize(testcase);
- Assert.AreEqual("\"foo\"", result);
-
- var testcase2 = 1;
- result = Utils.Serialize(testcase2);
- Assert.AreEqual("1", result);
- }
-
- [Test]
- public void TestSerializeDictionary()
- {
- var test = new Dictionary<string, string>
- {
- {"a", "b"},
- {"c", "d/e"}
- };
- var result = Utils.SerializeDictionary(test);
- var expected = "{\"a\":\"b\",\"c\":\"d\\/e\"}";
- Assert.AreEqual(expected, result);
- }
- }
-}
diff --git a/SendGrid/Tests/Tests.csproj b/SendGrid/Tests/Tests.csproj index df3bbe3..960aa9b 100644 --- a/SendGrid/Tests/Tests.csproj +++ b/SendGrid/Tests/Tests.csproj @@ -34,15 +34,6 @@ <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Microsoft.Threading.Tasks">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
- </Reference>
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
@@ -55,14 +46,34 @@ <Reference Include="pnunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll</HintPath>
</Reference>
+ <Reference Include="Smtpapi">
+ <HintPath>..\packages\smtpapi.1.0.0\lib\Smtpapi.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.IO">
+ <HintPath>..\packages\Microsoft.Bcl.1.1.6\lib\net40\System.IO.dll</HintPath>
+ </Reference>
<Reference Include="System.Net" />
+ <Reference Include="System.Net.Http, Version=2.2.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Net.Http.Extensions">
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.Extensions.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Net.Http.Primitives">
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.Primitives.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Net.Http.WebRequest, Version=2.2.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
+ </Reference>
<Reference Include="System.Runtime">
- <HintPath>..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Runtime.dll</HintPath>
+ <HintPath>..\packages\Microsoft.Bcl.1.1.6\lib\net40\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks">
- <HintPath>..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Threading.Tasks.dll</HintPath>
+ <HintPath>..\packages\Microsoft.Bcl.1.1.6\lib\net40\System.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@@ -71,34 +82,17 @@ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="TestHeader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="TestJsonUtils.cs" />
<Compile Include="TestSendgrid.cs" />
- <Compile Include="TestSendgridMessageSetup.cs" />
- <Compile Include="TestTreeNode.cs" />
- <Compile Include="TestUtils.cs" />
<Compile Include="Transport\TestWeb.cs" />
- <Compile Include="Transport\TestSMTP.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\SendGridMail\Mail.csproj">
- <Project>{3C687BEF-FF50-44AD-8315-2D4237281AF8}</Project>
- <Name>Mail</Name>
- </ProjectReference>
- </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <Import Project="..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />
- <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
- <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
- <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
- </Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
@@ -106,4 +100,15 @@ <Target Name="AfterBuild">
</Target>
-->
+ <ItemGroup>
+ <ProjectReference Include="..\SendGridMail\Mail.csproj">
+ <Project>{3C687BEF-FF50-44AD-8315-2D4237281AF8}</Project>
+ <Name>Mail</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" />
+ <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
+ <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
+ <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
+ </Target>
</Project>
\ No newline at end of file diff --git a/SendGrid/Tests/Transport/TestSMTP.cs b/SendGrid/Tests/Transport/TestSMTP.cs deleted file mode 100755 index 24c1a47..0000000 --- a/SendGrid/Tests/Transport/TestSMTP.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System;
-using System.Net;
-using System.Net.Mail;
-using Moq;
-using NUnit.Framework;
-using SendGridMail;
-using SendGridMail.Transport;
-
-namespace Tests.Transport
-{
- [TestFixture]
- public class TestSMTP
- {
- [Test]
- public void TestDeliver()
- {
- var mockMessage = new Mock<ISendGrid>();
- var mime = new MailMessage("test-from@sendgrid.com", "test-to@sendgrid.com", "this is a test", "it is only a test");
- mockMessage.Setup(foo => foo.CreateMimeMessage()).Returns(mime);
- var message = mockMessage.Object;
-
- var mockClient = new Mock<SMTP.ISmtpClient>();
- mockClient.Setup(foo => foo.Send(mime));
- var client = mockClient.Object;
- var credentials = new NetworkCredential("username", "password");
- var test = SMTP.GetInstance(client, credentials);
- test.Deliver(message);
-
- mockClient.Verify(foo => foo.Send(mime), Times.Once());
- mockMessage.Verify(foo => foo.CreateMimeMessage(), Times.Once());
- }
-
- [Test]
- public void TestConstructor()
- {
- //Test on defaults of port 25 and
- var mock = new Mock<SMTP.ISmtpClient>();
- mock.SetupProperty(foo => foo.EnableSsl);
- var client = mock.Object;
- var credentials = new NetworkCredential("username", "password");
- SMTP.GetInstance(client, credentials);
- mock.Verify(foo => foo.EnableSsl, Times.Never());
-
- mock = new Mock<SMTP.ISmtpClient>();
- mock.SetupProperty(foo => foo.EnableSsl);
- client = mock.Object;
- credentials = new NetworkCredential("username", "password");
- SMTP.GetInstance(client, credentials, port:SMTP.SslPort);
- mock.VerifySet(foo => foo.EnableSsl = true);
-
- mock = new Mock<SMTP.ISmtpClient>();
- mock.SetupProperty(foo => foo.EnableSsl);
- client = mock.Object;
- credentials = new NetworkCredential("username", "password");
- try
- {
- SMTP.GetInstance(client, credentials, port: SMTP.TlsPort);
- Assert.Fail("should have thrown an unsupported port exception");
- }
- catch (NotSupportedException ex)
- {
- Assert.AreEqual("TLS not supported", ex.Message);
- }
-
-
- }
- }
-}
diff --git a/SendGrid/Tests/Transport/TestWeb.cs b/SendGrid/Tests/Transport/TestWeb.cs index ac69dd2..d87a423 100755..100644 --- a/SendGrid/Tests/Transport/TestWeb.cs +++ b/SendGrid/Tests/Transport/TestWeb.cs @@ -7,7 +7,6 @@ using System.Text; using Moq;
using NUnit.Framework;
using SendGridMail;
-using SendGridMail.Transport;
namespace Tests.Transport
{
diff --git a/SendGrid/Tests/packages.config b/SendGrid/Tests/packages.config index c54cf7e..a4b4637 100644 --- a/SendGrid/Tests/packages.config +++ b/SendGrid/Tests/packages.config @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Microsoft.Bcl" version="1.0.19" targetFramework="net40" />
- <package id="Microsoft.Bcl.Async" version="1.0.16" targetFramework="net40" />
- <package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="net40" />
- <package id="Moq" version="4.0.10827" />
+ <package id="Microsoft.Bcl" version="1.1.6" targetFramework="net40" />
+ <package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net40" />
+ <package id="Microsoft.Net.Http" version="2.2.18" targetFramework="net40" />
<package id="NUnit" version="2.5.10.11092" />
+ <package id="smtpapi" version="1.0.0" targetFramework="net40" />
</packages>
\ No newline at end of file diff --git a/SendGrid/packages/repositories.config b/SendGrid/packages/repositories.config index 2257ed7..d0c8ba7 100644 --- a/SendGrid/packages/repositories.config +++ b/SendGrid/packages/repositories.config @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="utf-8"?>
<repositories>
+ <repository path="../SendGridMail/packages.config" />
+ <repository path="../Tests/packages.config" />
<repository path="..\SendGridMail\packages.config" />
<repository path="..\Tests\packages.config" />
</repositories>
\ No newline at end of file |