summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail
diff options
context:
space:
mode:
Diffstat (limited to 'SendGrid/SendGridMail')
-rw-r--r--SendGrid/SendGridMail/ISendGrid.cs36
-rw-r--r--SendGrid/SendGridMail/Mail.csproj8
-rw-r--r--SendGrid/SendGridMail/SendGrid.cs58
-rw-r--r--SendGrid/SendGridMail/StreamedFileBody.cs2
-rw-r--r--SendGrid/SendGridMail/Transport/ITransport.cs7
-rw-r--r--SendGrid/SendGridMail/Transport/Web.cs55
-rw-r--r--SendGrid/SendGridMail/packages.config5
7 files changed, 110 insertions, 61 deletions
diff --git a/SendGrid/SendGridMail/ISendGrid.cs b/SendGrid/SendGridMail/ISendGrid.cs
index 1d5ea8f..38a931a 100644
--- a/SendGrid/SendGridMail/ISendGrid.cs
+++ b/SendGrid/SendGridMail/ISendGrid.cs
@@ -63,6 +63,16 @@ namespace SendGrid
/// </param>
void AddTo(IDictionary<String, IDictionary<String, String>> addresssInfo);
+ /// <summary>
+ /// Defines a mapping between a replacement string in the text of the message to a section of
+ /// substitution values to be used
+ /// </summary>
+ /// <param name="replacementTag">the string in the email that you'll replace eg. '-itemsOrdered-'</param>
+ /// <param name="sectionValue">
+ /// The content that will be substituted in for the replacementTag
+ /// </param>
+ void AddSection(String replacementTag, String sectionValue);
+
/// <summary>
/// Defines a mapping between a replacement string in the text of the message to a list of
/// substitution values to be used, one per each recipient, in the same order as the recipients were added.
@@ -81,6 +91,12 @@ namespace SendGrid
/// <param name="identifiers">parameter substitutionValues pairs to be passed back on event notification</param>
void AddUniqueArgs(IDictionary<String, String> identifiers);
+ /// <summary>
+ /// This sets the suppression group id for this email.
+ /// </summary>
+ /// <param name="id">the id of the suppression group</param>
+ void SetAsmGroupId(int id);
+
/// <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.
@@ -95,6 +111,24 @@ namespace SendGrid
/// <param name="categories">categories applied to the message</param>
void SetCategories(IEnumerable<String> categories);
+ /// <summary>
+ /// This sets the IP Pool for this email.
+ /// </summary>
+ /// <param name="pool">The name of the pool with which to send the message.</param>
+ void SetIpPool(String pool);
+
+ /// <summary>
+ /// Define a send_at timestamp to schedule this send for the future.
+ /// </summary>
+ /// <param name="sendTime">The time at which to send the email</param>
+ void SetSendAt(DateTime sendTime);
+
+ /// <summary>
+ /// Define a send_each_at timestamp to schedule individual send times per message
+ /// </summary>
+ /// <param name="sendTimes">The times at which to send the emails</param>
+ void SetSendEachAt(IEnumerable<DateTime> sendTimes);
+
/// <summary>
/// Add an attachment to the message.
/// </summary>
@@ -108,6 +142,8 @@ namespace SendGrid
/// <param name="name">Name of file to be attached</param>
void AddAttachment(Stream stream, String name);
+ void EmbedStreamImage(Stream stream, String name);
+
/// <summary>
/// GetRecipients returns a list of all the recepients by retrieving the to, cc, and bcc lists.
/// </summary>
diff --git a/SendGrid/SendGridMail/Mail.csproj b/SendGrid/SendGridMail/Mail.csproj
index 998226f..f95d118 100644
--- a/SendGrid/SendGridMail/Mail.csproj
+++ b/SendGrid/SendGridMail/Mail.csproj
@@ -88,9 +88,9 @@
</DebugType>
</PropertyGroup>
<ItemGroup>
- <Reference Include="SendGrid.SmtpApi, Version=1.2.1.0, Culture=neutral, PublicKeyToken=2ae73662c35d80e4, processorArchitecture=MSIL">
+ <Reference Include="SendGrid.SmtpApi, Version=1.3.1.0, Culture=neutral, PublicKeyToken=2ae73662c35d80e4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\SendGrid.SmtpApi.1.2.1\lib\net40\SendGrid.SmtpApi.dll</HintPath>
+ <HintPath>..\packages\SendGrid.SmtpApi.1.3.1\lib\net40\SendGrid.SmtpApi.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -108,9 +108,7 @@
<Compile Include="Transport\Web.cs" />
</ItemGroup>
<ItemGroup>
- <None Include="packages.config">
- <SubType>Designer</SubType>
- </None>
+ <None Include="packages.config" />
<None Include="sendgrid-csharp.snk" />
</ItemGroup>
<ItemGroup>
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs
index 1533a46..1581f40 100644
--- a/SendGrid/SendGridMail/SendGrid.cs
+++ b/SendGrid/SendGridMail/SendGrid.cs
@@ -20,7 +20,9 @@ namespace SendGrid
private static readonly Regex TemplateTest = new Regex(@"<%\s*body\s*%>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex TextUnsubscribeTest = new Regex(@"<%\s*%>", RegexOptions.Compiled);
private static readonly Regex HtmlUnsubscribeTest = new Regex(@"<%\s*([^\s%]+\s?)+\s*%>", RegexOptions.Compiled);
- #endregion
+ private const string SinkHost = "sink.sendgrid.net";
+
+ #endregion
#region Initialization and Constructors
@@ -96,7 +98,16 @@ namespace SendGrid
public MailAddress[] To
{
- get { return _message.To.ToArray(); }
+ get
+ {
+ if (_sendToSink)
+ {
+ return _message.To
+ .Select(ma => new MailAddress(string.Format("{0}_at_{1}@{2}", ma.User, ma.Host, SinkHost), ma.DisplayName))
+ .ToArray();
+ }
+ return _message.To.ToArray();
+ }
set
{
_message.To.Clear();
@@ -151,8 +162,9 @@ namespace SendGrid
private List<String> _attachments = new List<String>();
private Dictionary<String, MemoryStream> _streamedAttachments = new Dictionary<string, MemoryStream>();
private Dictionary<String, String> _contentImages = new Dictionary<string, string>();
+ private bool _sendToSink;
- public void AddTo(String address)
+ public void AddTo(String address)
{
var mailAddress = new MailAddress(address);
_message.To.Add(mailAddress);
@@ -222,11 +234,36 @@ namespace SendGrid
Header.AddSubstitution(replacementTag, substitutionValues);
}
+ public void AddSection(String replacementTag, String sectionValue)
+ {
+ Header.AddSection(replacementTag, sectionValue);
+ }
+
public void AddUniqueArgs(IDictionary<String, String> identifiers)
{
Header.AddUniqueArgs(identifiers);
}
+ public void SetAsmGroupId(int id)
+ {
+ Header.SetAsmGroupId(id);
+ }
+
+ public void SetIpPool(string pool)
+ {
+ Header.SetIpPool(pool);
+ }
+
+ public void SetSendAt(DateTime sendTime)
+ {
+ Header.SetSendAt(sendTime);
+ }
+
+ public void SetSendEachAt(IEnumerable<DateTime> sendTimes)
+ {
+ Header.SetSendEachAt(sendTimes);
+ }
+
public void SetCategory(String category)
{
Header.SetCategory(category);
@@ -245,6 +282,16 @@ namespace SendGrid
StreamedAttachments[name] = ms;
}
+ public void EmbedStreamImage(Stream stream, String name)
+ {
+ var ms = new MemoryStream();
+ stream.CopyTo(ms);
+ ms.Seek(0, SeekOrigin.Begin);
+ StreamedAttachments[name] = ms;
+
+ _contentImages[name] = name;
+ }
+
public void AddAttachment(String filePath)
{
_attachments.Add(filePath);
@@ -265,6 +312,11 @@ namespace SendGrid
headers.Keys.ToList().ForEach(key => Headers[key] = headers[key]);
}
+ public void SendToSink(bool value = true)
+ {
+ _sendToSink = value;
+ }
+
#endregion
#region SMTP API Functions
diff --git a/SendGrid/SendGridMail/StreamedFileBody.cs b/SendGrid/SendGridMail/StreamedFileBody.cs
index faa9d59..125fe24 100644
--- a/SendGrid/SendGridMail/StreamedFileBody.cs
+++ b/SendGrid/SendGridMail/StreamedFileBody.cs
@@ -6,7 +6,7 @@ using System.Text;
namespace SendGridMail
{
- public class StreamedFileBody : Body
+ public class StreamedFileBody
{
private string _name;
private string _filename;
diff --git a/SendGrid/SendGridMail/Transport/ITransport.cs b/SendGrid/SendGridMail/Transport/ITransport.cs
index 26ea635..94a2d7f 100644
--- a/SendGrid/SendGridMail/Transport/ITransport.cs
+++ b/SendGrid/SendGridMail/Transport/ITransport.cs
@@ -9,13 +9,6 @@ namespace SendGrid
/// </summary>
public interface ITransport
{
- /// <summary>
- /// Delivers a message using the protocol of the derived class
- /// </summary>
- /// <param name="message">the message to be delivered</param>
- void Deliver(ISendGrid message);
-
-
/// <summary>
/// Asynchronously delivers a message using the protocol of the derived class
/// </summary>
diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs
index a125833..81e7c72 100644
--- a/SendGrid/SendGridMail/Transport/Web.cs
+++ b/SendGrid/SendGridMail/Transport/Web.cs
@@ -19,11 +19,10 @@ namespace SendGrid
#region Properties
//TODO: Make this configurable
- public const String BaseUrl = "api.sendgrid.com";
- public const String Endpoint = "/api/mail.send";
-
+ public const String Endpoint = "https://api.sendgrid.com/api/mail.send.xml";
+
private readonly NetworkCredential _credentials;
- private readonly TimeSpan _timeout;
+ private readonly HttpClient _client;
#endregion
@@ -31,11 +30,8 @@ namespace SendGrid
/// Creates a new Web interface for sending mail
/// </summary>
/// <param name="credentials">SendGridMessage user parameters</param>
- public Web(NetworkCredential credentials)
- {
- _credentials = credentials;
- _timeout = TimeSpan.FromSeconds(100);
- }
+ public Web(NetworkCredential credentials)
+ : this(credentials, TimeSpan.FromSeconds(100)) { }
/// <summary>
/// Creates a new Web interface for sending mail.
@@ -44,30 +40,13 @@ namespace SendGrid
/// <param name="httpTimeout">HTTP request timeout</param>
public Web(NetworkCredential credentials, TimeSpan httpTimeout)
{
- _credentials = credentials;
- _timeout = httpTimeout;
- }
-
- /// <summary>
- /// Delivers a message over SendGrid's Web interface
- /// </summary>
- /// <param name="message"></param>
- public void Deliver(ISendGrid message)
- {
- var client = new HttpClient();
-
- client.BaseAddress = new Uri("https://" + BaseUrl);
- client.Timeout = _timeout;
-
+ _credentials = credentials;
+ _client = new HttpClient();
+
var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
- client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "sendgrid/" + version + ";csharp");
-
- var content = new MultipartFormDataContent();
- AttachFormParams(message, content);
- AttachFiles(message, content);
- var response = client.PostAsync(Endpoint + ".xml", content).Result;
- ErrorChecker.CheckForErrors(response);
- }
+ _client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "sendgrid/" + version + ";csharp");
+ _client.Timeout = httpTimeout;
+ }
/// <summary>
/// Asynchronously delivers a message over SendGrid's Web interface
@@ -75,19 +54,11 @@ namespace SendGrid
/// <param name="message"></param>
public async Task DeliverAsync(ISendGrid message)
{
- var client = new HttpClient();
-
- client.BaseAddress = new Uri("https://" + BaseUrl);
- client.Timeout = _timeout;
-
- var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
- client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "sendgrid/" + version + ";csharp");
-
var content = new MultipartFormDataContent();
AttachFormParams(message, content);
AttachFiles(message, content);
- var response = await client.PostAsync(Endpoint + ".xml", content);
- await ErrorChecker.CheckForErrorsAsync(response);
+ var response = await _client.PostAsync(Endpoint + ".xml", content);
+ await ErrorChecker.CheckForErrorsAsync(response);
}
#region Support Methods
diff --git a/SendGrid/SendGridMail/packages.config b/SendGrid/SendGridMail/packages.config
index 606bf16..030933b 100644
--- a/SendGrid/SendGridMail/packages.config
+++ b/SendGrid/SendGridMail/packages.config
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="SendGrid.SmtpApi" version="1.1.3" targetFramework="net40" />
- <package id="SendGrid.SmtpApi" version="1.2.1" targetFramework="net45" />
-</packages>
+ <package id="SendGrid.SmtpApi" version="1.3.1" targetFramework="net45" />
+</packages> \ No newline at end of file