diff options
Diffstat (limited to 'SendGrid/SendGridMail/SendGrid.cs')
-rwxr-xr-x | SendGrid/SendGridMail/SendGrid.cs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs index 42214b7..4a14211 100755 --- a/SendGrid/SendGridMail/SendGrid.cs +++ b/SendGrid/SendGridMail/SendGrid.cs @@ -1,6 +1,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
+using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
@@ -275,6 +276,13 @@ namespace SendGridMail }
}
+ private Dictionary<String, MemoryStream> _streamedAttachments = new Dictionary<string, MemoryStream>();
+ public Dictionary<String, MemoryStream> StreamedAttachments
+ {
+ get { return _streamedAttachments; }
+ set { _streamedAttachments = value; }
+ }
+
private List<String> _attachments = new List<String>();
public String[] Attachments
{
@@ -298,6 +306,12 @@ namespace SendGridMail Header.SetCategory(category);
}
+ public void AddAttachment(Stream stream, String name)
+ {
+ MemoryStream ms = new MemoryStream();
+ stream.CopyTo(ms);
+ StreamedAttachments[name] = ms;
+ }
public void AddAttachment(String filePath)
{
@@ -496,6 +510,15 @@ namespace SendGridMail }
}
+ if(StreamedAttachments != null)
+ {
+ foreach (var attachment in StreamedAttachments)
+ {
+ attachment.Value.Position = 0;
+ message.Attachments.Add(new Attachment(attachment.Value, attachment.Key));
+ }
+ }
+
if (Text != null)
{
AlternateView plainView = AlternateView.CreateAlternateViewFromString(Text, null, "text/plain");
|