diff options
author | Tyler Bischel <tyler.bischel@sendgrid.com> | 2012-01-12 10:33:04 -0800 |
---|---|---|
committer | Tyler Bischel <tyler.bischel@sendgrid.com> | 2012-01-12 10:33:04 -0800 |
commit | 9a1ef469c68e982088721c571416ffd6a7dba5a1 (patch) | |
tree | 3a83a7d026645d31bfb0801b8805a86b540d927f /SendGrid/SendGridMail/SendGrid.cs | |
parent | 68f58e77326f4fd3e2347014790f6298ab8d76ae (diff) | |
download | sendgrid-csharp-9a1ef469c68e982088721c571416ffd6a7dba5a1.zip sendgrid-csharp-9a1ef469c68e982088721c571416ffd6a7dba5a1.tar.gz sendgrid-csharp-9a1ef469c68e982088721c571416ffd6a7dba5a1.tar.bz2 |
refactored attachments, fixed bug in headers
Diffstat (limited to 'SendGrid/SendGridMail/SendGrid.cs')
-rwxr-xr-x | SendGrid/SendGridMail/SendGrid.cs | 59 |
1 files changed, 15 insertions, 44 deletions
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs index 5031c6f..04330d1 100755 --- a/SendGrid/SendGridMail/SendGrid.cs +++ b/SendGrid/SendGridMail/SendGrid.cs @@ -235,7 +235,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 +251,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()
@@ -471,7 +439,7 @@ 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)
{
@@ -500,7 +468,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);
}
}
}
|