diff options
Diffstat (limited to 'SendGrid/SendGridMail')
-rw-r--r-- | SendGrid/SendGridMail/Header.cs | 199 | ||||
-rw-r--r-- | SendGrid/SendGridMail/IHeader.cs | 95 | ||||
-rw-r--r--[-rwxr-xr-x] | SendGrid/SendGridMail/ISendGrid.cs | 5 | ||||
-rw-r--r-- | SendGrid/SendGridMail/Mail.csproj | 7 | ||||
-rw-r--r-- | SendGrid/SendGridMail/SendGrid.cs | 54 | ||||
-rw-r--r--[-rwxr-xr-x] | SendGrid/SendGridMail/Transport/ITransport.cs | 2 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/Transport/SMTP.cs | 132 | ||||
-rw-r--r-- | SendGrid/SendGridMail/Transport/Web.cs | 5 | ||||
-rwxr-xr-x | SendGrid/SendGridMail/Utils.cs | 31 | ||||
-rw-r--r-- | SendGrid/SendGridMail/packages.config | 1 |
10 files changed, 38 insertions, 493 deletions
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 |