diff --git a/src/NetCore.Utilities.Email.SendGrid.sln b/src/NetCore.Utilities.Email.SendGrid.sln
index 5a95dad..b6858be 100644
--- a/src/NetCore.Utilities.Email.SendGrid.sln
+++ b/src/NetCore.Utilities.Email.SendGrid.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.30804.86
+# Visual Studio Version 17
+VisualStudioVersion = 17.2.32516.85
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Utilities.Email.SendGrid", "NetCore.Utilities.Email.SendGrid\NetCore.Utilities.Email.SendGrid.csproj", "{48F8F9BE-5579-4B92-AF46-194F755ECAB0}"
EndProject
diff --git a/src/NetCore.Utilities.Email.SendGrid/NetCore.Utilities.Email.SendGrid.csproj b/src/NetCore.Utilities.Email.SendGrid/NetCore.Utilities.Email.SendGrid.csproj
index 784e59e..1f4fa3f 100644
--- a/src/NetCore.Utilities.Email.SendGrid/NetCore.Utilities.Email.SendGrid.csproj
+++ b/src/NetCore.Utilities.Email.SendGrid/NetCore.Utilities.Email.SendGrid.csproj
@@ -44,7 +44,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/src/NetCore.Utilities.Email.SendGrid/SendGridMessageBuilder.cs b/src/NetCore.Utilities.Email.SendGrid/SendGridMessageBuilder.cs
index bab3768..714e76a 100644
--- a/src/NetCore.Utilities.Email.SendGrid/SendGridMessageBuilder.cs
+++ b/src/NetCore.Utilities.Email.SendGrid/SendGridMessageBuilder.cs
@@ -85,20 +85,7 @@ public SendGridMessage CreateMessage(string from, string fromName, string to, IE
if (!string.IsNullOrEmpty(fromName))
fromAddress.Name = fromName;
var recipients = new List {new EmailAddress(to)};
- if (cc != null)
- {
- foreach (var item in cc)
- {
- try
- {
- recipients.Add(new EmailAddress(item));
- }
- catch (Exception ex)
- {
- _logger.LogWarning(ex, $"Unable to add {item} to email copy list");
- }
- }
- }
+
//Handle subjects
if (_serviceOptions.AddEnvironmentSuffix && !_hostingEnvironment.IsProduction())
@@ -115,11 +102,30 @@ public SendGridMessage CreateMessage(string from, string fromName, string to, IE
var plainTextBody = Regex.Replace(bodyHtml, "<[^>]*>", "");
//Build message
+ SendGridMessage message = null;
if (recipients.Count == 1)
- return MailHelper.CreateSingleEmail(fromAddress, recipients[0], subject, plainTextBody, bodyHtml);
+ message = MailHelper.CreateSingleEmail(fromAddress, recipients[0], subject, plainTextBody, bodyHtml);
+ else
+ message = MailHelper.CreateSingleEmailToMultipleRecipients(fromAddress, recipients, subject, plainTextBody, bodyHtml);
+
+ //Add CC later based on limitation of SendGrid API
+ if (cc != null)
+ {
+ foreach (var item in cc)
+ {
+ try
+ {
+ var toAdd = new EmailAddress(item);
+ message.AddCc(toAdd);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogWarning(ex, $"Unable to add {item} to email copy list");
+ }
+ }
+ }
- return MailHelper.CreateSingleEmailToMultipleRecipients(fromAddress, recipients, subject, plainTextBody,
- bodyHtml);
+ return message;
}
///