summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail
diff options
context:
space:
mode:
Diffstat (limited to 'SendGrid/SendGridMail')
-rwxr-xr-xSendGrid/SendGridMail/Header.cs11
-rwxr-xr-xSendGrid/SendGridMail/Properties/AssemblyInfo.cs7
-rwxr-xr-xSendGrid/SendGridMail/SendGrid.cs71
3 files changed, 39 insertions, 50 deletions
diff --git a/SendGrid/SendGridMail/Header.cs b/SendGrid/SendGridMail/Header.cs
index c1138d8..860ebed 100755
--- a/SendGrid/SendGridMail/Header.cs
+++ b/SendGrid/SendGridMail/Header.cs
@@ -7,6 +7,7 @@ namespace SendGridMail
{
public class Header : IHeader
{
+ private const string SendgridHeader = "X-Smtpapi";
private readonly HeaderSettingsNode _settings;
public Header()
@@ -16,7 +17,7 @@ namespace SendGridMail
public void AddSubVal(string tag, IEnumerable<string> substitutions)
{
- var keys = new List<String> {"data", "sub", tag};
+ var keys = new List<String> {"sub", tag};
_settings.AddArray(keys, substitutions);
}
@@ -24,7 +25,7 @@ namespace SendGridMail
{
foreach (var key in identifiers.Keys)
{
- var keys = new List<String> {"data", "unique_args", key};
+ var keys = new List<String> {"unique_args", key};
var value = identifiers[key];
_settings.AddSetting(keys, value);
}
@@ -32,7 +33,7 @@ namespace SendGridMail
public void SetCategory(string category)
{
- var keys = new List<String> {"data", "category"};
+ var keys = new List<String> {"category"};
_settings.AddSetting(keys, category);
}
@@ -48,13 +49,13 @@ namespace SendGridMail
public void AddFilterSetting(string filter, IEnumerable<string> settings, string value)
{
- var keys = new List<string>() { "data", "filters", filter, "settings" }.Concat(settings).ToList();
+ var keys = new List<string>() {"filters", filter, "settings" }.Concat(settings).ToList();
_settings.AddSetting(keys, value);
}
public void AddHeader(MailMessage mime)
{
- mime.Headers.Add("x-smtpapi", AsJson());
+ mime.Headers.Add(SendgridHeader, AsJson());
}
public String AsJson()
diff --git a/SendGrid/SendGridMail/Properties/AssemblyInfo.cs b/SendGrid/SendGridMail/Properties/AssemblyInfo.cs
index 0cefaba..0108aa9 100755
--- a/SendGrid/SendGridMail/Properties/AssemblyInfo.cs
+++ b/SendGrid/SendGridMail/Properties/AssemblyInfo.cs
@@ -23,6 +23,13 @@ using System.Runtime.InteropServices;
[assembly: Guid("193fa200-8430-4206-aacd-2d2bb2dfa6cf")]
[assembly: InternalsVisibleTo("Tests")]
+[assembly:InternalsVisibleTo("DynamicProxyGenAssembly2," +
+"1310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b" +
+"PublicKey=002400000480000094000000060200000024000052534" +
+"3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d926665" +
+"4753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb" +
+"4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c486" +
+"1eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
// Version information for an assembly consists of the following four values:
//
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs
index 2f44c38..2e238f5 100755
--- a/SendGrid/SendGridMail/SendGrid.cs
+++ b/SendGrid/SendGridMail/SendGrid.cs
@@ -236,6 +236,12 @@ namespace SendGridMail
}
public Attachment[] Attachments { get; set; }
+ private List<Attachment> _attachments = new List<Attachment>();
+ public Attachment[] Attachments
+ {
+ get { return _attachments.ToArray(); }
+ set { _attachments = value.ToList(); }
+ }
public void AddSubVal(String tag, params String[] value)
{
@@ -246,55 +252,18 @@ namespace SendGridMail
public void AddAttachment(String filePath)
{
var data = new Attachment(filePath, MediaTypeNames.Application.Octet);
-
- if (Attachments == null)
- {
- Attachments = new Attachment[1];
- Attachments[0] = data;
- }
- else
- {
- var i = Attachments.Count();
- var tmp = new Attachment[i + 1];
- Attachments.CopyTo(tmp, 0);
- Attachments = tmp;
- Attachments[i] = data;
- }
+ _attachments.Add(data);
}
public void AddAttachment(Attachment attachment)
{
- if (Attachments == null)
- {
- Attachments = new Attachment[1];
- Attachments[0] = attachment;
- }
- else
- {
- var i = Attachments.Count();
- var tmp = new Attachment[i + 1];
- Attachments.CopyTo(tmp, 0);
- Attachments = tmp;
- Attachments[i] = attachment;
- }
+ _attachments.Add(attachment);
}
public void AddAttachment(Stream attachment, ContentType type)
{
- var data = new Attachment(attachment, type);
- if (Attachments == null)
- {
- Attachments = new Attachment[1];
- Attachments[0] = data;
- }
- else
- {
- var i = Attachments.Count();
- var tmp = new Attachment[i + 1];
- Attachments.CopyTo(tmp, 0);
- Attachments = tmp;
- Attachments[i] = data;
- }
+ var data = new Attachment(attachment, type);
+ _attachments.Add(data);
}
public IEnumerable<String> GetRecipients()
@@ -404,6 +373,7 @@ namespace SendGridMail
Header.AddFilterSetting(filter, new List<string>(){ "text" }, text);
Header.AddFilterSetting(filter, new List<string>(){ "html" }, html);
Header.AddFilterSetting(filter, new List<string>(){ "replace"}, replace);
+ Header.AddFilterSetting(filter, new List<string>(){ "url"}, url);
Header.AddFilterSetting(filter, new List<string>(){ "landing" }, landing);
}
@@ -421,11 +391,11 @@ namespace SendGridMail
var filter = this._filters["GoogleAnalytics"];
Header.Enable(filter);
- Header.AddFilterSetting(filter, new List<string>(){ "source " }, source);
+ Header.AddFilterSetting(filter, new List<string>(){ "source" }, source);
Header.AddFilterSetting(filter, new List<string>(){ "medium" }, medium);
Header.AddFilterSetting(filter, new List<string>(){ "term" }, term);
Header.AddFilterSetting(filter, new List<string>(){ "content" }, content);
- Header.AddFilterSetting(filter, new List<string>(){ "compaign" }, campaign);
+ Header.AddFilterSetting(filter, new List<string>(){ "campaign" }, campaign);
}
public void EnableTemplate(string html)
@@ -460,7 +430,15 @@ namespace SendGridMail
String smtpapi = Header.AsJson();
if (!String.IsNullOrEmpty(smtpapi))
- message.Headers.Add("X-SmtpApi", "{" + smtpapi + "}");
+ message.Headers.Add("X-Smtpapi", smtpapi);
+
+ if(Attachments != null)
+ {
+ foreach (Attachment attachment in Attachments)
+ {
+ message.Attachments.Add(attachment);
+ }
+ }
if(Attachments != null)
{
@@ -489,7 +467,10 @@ namespace SendGridMail
public void Mail()
{
- throw new NotImplementedException();
+ SmtpClient client = new SmtpClient("localhost");
+ client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
+ client.PickupDirectoryLocation = @"C:\temp";
+ client.Send(message);
}
}
}