diff options
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);
}
}
}
|