summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail
diff options
context:
space:
mode:
Diffstat (limited to 'SendGrid/SendGridMail')
-rw-r--r--SendGrid/SendGridMail/ISendGrid.cs2
-rw-r--r--SendGrid/SendGridMail/SendGrid.cs50
-rw-r--r--SendGrid/SendGridMail/Transport/Web.cs19
3 files changed, 66 insertions, 5 deletions
diff --git a/SendGrid/SendGridMail/ISendGrid.cs b/SendGrid/SendGridMail/ISendGrid.cs
index 6c9d3fa..1d5ea8f 100644
--- a/SendGrid/SendGridMail/ISendGrid.cs
+++ b/SendGrid/SendGridMail/ISendGrid.cs
@@ -16,6 +16,8 @@ namespace SendGrid
MailAddress From { get; set; }
MailAddress[] To { get; set; }
+ MailAddress[] Cc { get; set; }
+ MailAddress[] Bcc { get; set; }
MailAddress[] ReplyTo { get; set; }
Dictionary<String, MemoryStream> StreamedAttachments { get; set; }
String[] Attachments { get; set; }
diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs
index 667f94d..1533a46 100644
--- a/SendGrid/SendGridMail/SendGrid.cs
+++ b/SendGrid/SendGridMail/SendGrid.cs
@@ -107,6 +107,32 @@ namespace SendGrid
}
}
+ public MailAddress[] Cc
+ {
+ get { return _message.CC.ToArray(); }
+ set
+ {
+ _message.CC.Clear();
+ foreach (var mailAddress in value)
+ {
+ _message.CC.Add(mailAddress);
+ }
+ }
+ }
+
+ public MailAddress[] Bcc
+ {
+ get { return _message.Bcc.ToArray(); }
+ set
+ {
+ _message.Bcc.Clear();
+ foreach (var mailAddress in value)
+ {
+ _message.Bcc.Add(mailAddress);
+ }
+ }
+ }
+
public String Subject
{
get { return _message.Subject; }
@@ -148,7 +174,29 @@ namespace SendGrid
}
}
- public Dictionary<String, MemoryStream> StreamedAttachments
+ public void AddCc(string address)
+ {
+ var mailAddress = new MailAddress(address);
+ _message.CC.Add(mailAddress);
+ }
+
+ public void AddCc(MailAddress address)
+ {
+ _message.CC.Add(address);
+ }
+
+ public void AddBcc(string address)
+ {
+ var mailAddress = new MailAddress(address);
+ _message.Bcc.Add(mailAddress);
+ }
+
+ public void AddBcc(MailAddress address)
+ {
+ _message.Bcc.Add(address);
+ }
+
+ public Dictionary<String, MemoryStream> StreamedAttachments
{
get { return _streamedAttachments; }
set { _streamedAttachments = value; }
diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs
index 750cb48..9784097 100644
--- a/SendGrid/SendGridMail/Transport/Web.cs
+++ b/SendGrid/SendGridMail/Transport/Web.cs
@@ -7,7 +7,6 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Xml;
-using Exceptions;
using SendGrid.SmtpApi;
// ReSharper disable MemberCanBePrivate.Global
@@ -46,6 +45,8 @@ namespace SendGrid
BaseAddress = new Uri("https://" + BaseUrl)
};
+ client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "sendgrid/4.0.1;csharp");
+
var content = new MultipartFormDataContent();
AttachFormParams(message, content);
AttachFiles(message, content);
@@ -198,8 +199,18 @@ namespace SendGrid
.Concat(message.To.ToList().Select(a => new KeyValuePair<String, String>("toname[]", a.DisplayName)))
.ToList();
}
- if (message.GetEmbeddedImages().Count > 0)
- {
+
+ if (message.Cc != null)
+ {
+ result.AddRange(message.Cc.Select(c => new KeyValuePair<string, string>("cc[]", c.Address)));
+ }
+
+ if (message.Bcc != null)
+ {
+ result.AddRange(message.Bcc.Select(c => new KeyValuePair<string, string>("bcc[]", c.Address)));
+ }
+
+ if (message.GetEmbeddedImages().Count > 0) {
result = result.Concat(message.GetEmbeddedImages().ToList().Select(x => new KeyValuePair<String, String>(string.Format("content[{0}]", x.Key), x.Value)))
.ToList();
}
@@ -220,4 +231,4 @@ namespace SendGrid
#endregion
}
-} \ No newline at end of file
+}