summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail/SendGrid.cs
diff options
context:
space:
mode:
authorEric Becking <eric.becking@sendgrid.com>2012-01-12 14:28:41 -0700
committerEric Becking <eric.becking@sendgrid.com>2012-01-12 14:28:41 -0700
commitfdca704e24d310c69184902dda41fdebc18fbcb5 (patch)
treef2185d6db3f04ab5337d25b9eb77cb2f692dce83 /SendGrid/SendGridMail/SendGrid.cs
parent26748c95a5092afbe48195710bce1ed3335ba1ee (diff)
downloadsendgrid-csharp-fdca704e24d310c69184902dda41fdebc18fbcb5.zip
sendgrid-csharp-fdca704e24d310c69184902dda41fdebc18fbcb5.tar.gz
sendgrid-csharp-fdca704e24d310c69184902dda41fdebc18fbcb5.tar.bz2
Web Api interface
Diffstat (limited to 'SendGrid/SendGridMail/SendGrid.cs')
-rwxr-xr-xSendGrid/SendGridMail/SendGrid.cs63
1 files changed, 50 insertions, 13 deletions
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs
index 06d1eaf..2f44c38 100755
--- a/SendGrid/SendGridMail/SendGrid.cs
+++ b/SendGrid/SendGridMail/SendGrid.cs
@@ -235,6 +235,8 @@ namespace SendGridMail
}
}
+ public Attachment[] Attachments { get; set; }
+
public void AddSubVal(String tag, params String[] value)
{
//let the system complain if they do something bad, since the function returns null
@@ -244,18 +246,55 @@ namespace SendGridMail
public void AddAttachment(String filePath)
{
var data = new Attachment(filePath, MediaTypeNames.Application.Octet);
- message.Attachments.Add(data);
+
+ 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;
+ }
}
public void AddAttachment(Attachment attachment)
{
- message.Attachments.Add(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;
+ }
}
public void AddAttachment(Stream attachment, ContentType type)
{
var data = new Attachment(attachment, type);
- message.Attachments.Add(data);
+ 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;
+ }
}
public IEnumerable<String> GetRecipients()
@@ -267,16 +306,6 @@ namespace SendGridMail
var rcpts = tos.Union(ccs.Union(bccs)).Select(address => address.Address);
return rcpts;
}
-
- private string Get(String field)
- {
- throw new NotImplementedException();
- }
-
- private void Set(String field, String value)
- {
- throw new NotImplementedException();
- }
#endregion
#region SMTP API Functions
@@ -433,6 +462,14 @@ namespace SendGridMail
if (!String.IsNullOrEmpty(smtpapi))
message.Headers.Add("X-SmtpApi", "{" + smtpapi + "}");
+ if(Attachments != null)
+ {
+ foreach (Attachment attachment in Attachments)
+ {
+ message.Attachments.Add(attachment);
+ }
+ }
+
if (Html != null)
{
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Html, null, "text/html");