diff options
Diffstat (limited to 'SendGrid/SendGridMail/SendGrid.cs')
-rwxr-xr-x | SendGrid/SendGridMail/SendGrid.cs | 63 |
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");
|