diff --git a/Source/StrongGrid.IntegrationTests/Tests/Mail.cs b/Source/StrongGrid.IntegrationTests/Tests/Mail.cs
index b389b10b..ce625aeb 100644
--- a/Source/StrongGrid.IntegrationTests/Tests/Mail.cs
+++ b/Source/StrongGrid.IntegrationTests/Tests/Mail.cs
@@ -59,14 +59,7 @@ public async Task RunAsync(IBaseClient client, TextWriter log, CancellationToken
};
var mailSettings = new MailSettings
{
- SandboxMode = new SandboxModeSettings
- {
- Enabled = true
- },
- BypassListManagement = new BypassListManagementSettings
- {
- Enabled = false
- },
+ SandboxModeEnabled = true,
Footer = new FooterSettings
{
Enabled = true,
diff --git a/Source/StrongGrid/Models/BypassListManagementSettings.cs b/Source/StrongGrid/Models/BypassListManagementSettings.cs
deleted file mode 100644
index 79baf4fe..00000000
--- a/Source/StrongGrid/Models/BypassListManagementSettings.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Newtonsoft.Json;
-
-namespace StrongGrid.Models
-{
- ///
- /// Allows you to bypass all unsubscribe groups and suppressions to ensure that the email is
- /// delivered to every single recipient. This should only be used in emergencies when it is
- /// absolutely necessary that every recipient receives your email. Ex: outage emails, or forgot
- /// password emails.
- ///
- public class BypassListManagementSettings
- {
- ///
- /// Gets or sets a value indicating whether this is enabled.
- ///
- ///
- /// true if enabled; otherwise, false.
- ///
- [JsonProperty("enable", NullValueHandling = NullValueHandling.Ignore)]
- public bool Enabled { get; set; }
- }
-}
diff --git a/Source/StrongGrid/Models/EmailAddressSetting.cs b/Source/StrongGrid/Models/EmailAddressSetting.cs
index a3135ade..d03cf3bf 100644
--- a/Source/StrongGrid/Models/EmailAddressSetting.cs
+++ b/Source/StrongGrid/Models/EmailAddressSetting.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using Newtonsoft.Json;
namespace StrongGrid.Models
{
@@ -13,7 +13,7 @@ public class EmailAddressSetting
///
/// true if enabled; otherwise, false.
///
- [JsonProperty("enabled", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonProperty("enabled")]
public bool Enabled { get; set; }
///
@@ -22,7 +22,7 @@ public class EmailAddressSetting
///
/// The email address.
///
- [JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)]
+ [JsonProperty("email")]
public string EmailAddress { get; set; }
}
}
diff --git a/Source/StrongGrid/Models/MailSettings.cs b/Source/StrongGrid/Models/MailSettings.cs
index 47890a81..bb08b5b4 100644
--- a/Source/StrongGrid/Models/MailSettings.cs
+++ b/Source/StrongGrid/Models/MailSettings.cs
@@ -1,5 +1,3 @@
-using Newtonsoft.Json;
-
namespace StrongGrid.Models
{
///
@@ -8,30 +6,50 @@ namespace StrongGrid.Models
public class MailSettings
{
///
- /// Gets or sets the bypass list management.
+ /// Gets or sets a value indicating whether to bypass all unsubscribe groups and suppressions to ensure that the email is delivered to every single recipient.
+ /// This should only be used in emergencies when it is absolutely necessary that every recipient receives your email.
+ ///
+ ///
+ /// This filter cannot be combined with any other bypass filters.
+ ///
+ public bool BypassListManagement { get; set; } = false;
+
+ ///
+ /// Gets or sets a value indicating whether to bypass the spam report list to ensure that the email is delivered to recipients.
+ /// Bounce and unsubscribe lists will still be checked; addresses on these other lists will not receive the message.
+ ///
+ ///
+ /// This filter cannot be combined with the bypass_list_management filter.
+ ///
+ public bool BypassSpamManagement { get; set; } = false;
+
+ ///
+ /// Gets or sets a value indicating whether to bypass the bounce list to ensure that the email is delivered to recipients.
+ /// Spam report and unsubscribe lists will still be checked; addresses on these other lists will not receive the message.
+ ///
+ ///
+ /// This filter cannot be combined with the bypass_list_management filter.
+ ///
+ public bool BypassBounceManagement { get; set; } = false;
+
+ ///
+ /// Gets or sets a value indicating whether to bypass the global unsubscribe list to ensure that the email is delivered to recipients.
+ /// Bounce and spam report lists will still be checked; addresses on these other lists will not receive the message.
+ /// This filter applies only to global unsubscribes and will not bypass group unsubscribes.
///
- ///
- /// The bypass list management.
- ///
- [JsonProperty("bypass_list_management", NullValueHandling = NullValueHandling.Ignore)]
- public BypassListManagementSettings BypassListManagement { get; set; }
+ ///
+ /// This filter cannot be combined with the bypass_list_management filter.
+ ///
+ public bool BypassUnsubscribeManagement { get; set; } = false;
///
/// Gets or sets the footer.
///
- ///
- /// The footer.
- ///
- [JsonProperty("footer", NullValueHandling = NullValueHandling.Ignore)]
public FooterSettings Footer { get; set; }
///
- /// Gets or sets the sandbox mode.
+ /// Gets or sets a value indicating whether the sandbox mode is enabled or not.
///
- ///
- /// The sandbox mode.
- ///
- [JsonProperty("sandbox_mode", NullValueHandling = NullValueHandling.Ignore)]
- public SandboxModeSettings SandboxMode { get; set; }
+ public bool SandboxModeEnabled { get; set; } = false;
}
}
diff --git a/Source/StrongGrid/Models/SandboxModeSettings.cs b/Source/StrongGrid/Models/SandboxModeSettings.cs
deleted file mode 100644
index 2b80eb39..00000000
--- a/Source/StrongGrid/Models/SandboxModeSettings.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using Newtonsoft.Json;
-
-namespace StrongGrid.Models
-{
- ///
- /// This allows you to send a test email to ensure that your request body is valid and formatted correctly.
- ///
- public class SandboxModeSettings
- {
- ///
- /// Gets or sets a value indicating whether this is enabled.
- ///
- ///
- /// true if enabled; otherwise, false.
- ///
- [JsonProperty("enable", NullValueHandling = NullValueHandling.Ignore)]
- public bool Enabled { get; set; }
- }
-}
diff --git a/Source/StrongGrid/Resources/ISettings.cs b/Source/StrongGrid/Resources/ISettings.cs
index 7996f1de..aa8912d6 100644
--- a/Source/StrongGrid/Resources/ISettings.cs
+++ b/Source/StrongGrid/Resources/ISettings.cs
@@ -310,6 +310,7 @@ public interface ISettings
///
/// The .
///
+ [Obsolete("As of august 2020, SendGrid has retired Spam Check mail settings.")]
Task GetSpamCheckMailSettingsAsync(string onBehalfOf = null, CancellationToken cancellationToken = default);
///
@@ -323,6 +324,7 @@ public interface ISettings
///
/// The .
///
+ [Obsolete("As of august 2020, SendGrid has retired Spam Check mail settings.")]
Task UpdateSpamCheckMailSettingsAsync(bool enabled, string postToUrl, int threshold, string onBehalfOf = null, CancellationToken cancellationToken = default);
///
diff --git a/Source/StrongGrid/Resources/Mail.cs b/Source/StrongGrid/Resources/Mail.cs
index c0aa1bab..e43ef825 100644
--- a/Source/StrongGrid/Resources/Mail.cs
+++ b/Source/StrongGrid/Resources/Mail.cs
@@ -191,6 +191,16 @@ public async Task SendAsync(
var isDynamicTemplate = Template.IsDynamic(templateId);
var personalizationConverter = new MailPersonalizationConverter(isDynamicTemplate);
+ // Manually serialize the MailSettings object because the shape of the C# class does not match the shape of the desired JSON.
+ // The C# class was intentionaly simplified to improve developers experience.
+ var mailSettingsJsonObject = new JObject();
+ mailSettingsJsonObject.AddPropertyIfValue("bypass_list_management/enable", mailSettings.BypassListManagement);
+ mailSettingsJsonObject.AddPropertyIfValue("bypass_spam_management/enable", mailSettings.BypassSpamManagement);
+ mailSettingsJsonObject.AddPropertyIfValue("bypass_bounce_management/enable", mailSettings.BypassBounceManagement);
+ mailSettingsJsonObject.AddPropertyIfValue("bypass_unsubscribe_management/enable", mailSettings.BypassUnsubscribeManagement);
+ mailSettingsJsonObject.AddPropertyIfValue("footer", mailSettings.Footer);
+ mailSettingsJsonObject.AddPropertyIfValue("sandbox_mode/enable", mailSettings.SandboxModeEnabled);
+
var data = new JObject();
data.AddPropertyIfValue("from", from);
data.AddPropertyIfValue("reply_to", replyTo);
@@ -203,7 +213,7 @@ public async Task SendAsync(
data.AddPropertyIfValue("batch_id", batchId);
data.AddPropertyIfValue("asm", unsubscribeOptions);
data.AddPropertyIfValue("ip_pool_name", ipPoolName);
- data.AddPropertyIfValue("mail_settings", mailSettings);
+ data.AddPropertyIfValue("mail_settings", mailSettingsJsonObject);
data.AddPropertyIfValue("tracking_settings", trackingSettings);
data.AddPropertyIfValue("personalizations", personalizationsCopy, personalizationConverter);