Skip to content

Commit

Permalink
(GH-391) Remove MailSettings.Bcc
Browse files Browse the repository at this point in the history
Also mark GetBccMailSettingsAsync and UpdateBccMailSettingsAsync as obsolete
  • Loading branch information
Jericho committed May 7, 2021
1 parent 347e328 commit eda7364
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
5 changes: 0 additions & 5 deletions Source/StrongGrid.IntegrationTests/Tests/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public async Task RunAsync(IBaseClient client, TextWriter log, CancellationToken
{
Enabled = true
},
Bcc = new BccSettings
{
Enabled = true,
EmailAddress = "[email protected]"
},
BypassListManagement = new BypassListManagementSettings
{
Enabled = false
Expand Down
10 changes: 10 additions & 0 deletions Source/StrongGrid.IntegrationTests/Tests/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public async Task RunAsync(IBaseClient client, TextWriter log, CancellationToken
await log.WriteLineAsync($" - {mailSetting.Title}: {(mailSetting.Enabled ? "Enabled" : "Not enabled")}").ConfigureAwait(false);
}

var bccSettings = await client.Settings.GetBccMailSettingsAsync(null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync("BCC settings retrieved:").ConfigureAwait(false);
await log.WriteLineAsync($" - Enabled: {bccSettings.Enabled}").ConfigureAwait(false);
await log.WriteLineAsync($" - Address: {bccSettings.EmailAddress}").ConfigureAwait(false);

var updatedBccSettings = await client.Settings.UpdateBccMailSettingsAsync(false, null, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync("BCC settings updated:").ConfigureAwait(false);
await log.WriteLineAsync($" - Enabled: {updatedBccSettings.Enabled}").ConfigureAwait(false);
await log.WriteLineAsync($" - Address: {updatedBccSettings.EmailAddress}").ConfigureAwait(false);

var clickTrackingSettings = await client.Settings.GetClickTrackingSettingsAsync(null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync("Click tracking settings retrieved:").ConfigureAwait(false);
await log.WriteLineAsync($" - Enabled in text content: {clickTrackingSettings.EnabledInTextContent}").ConfigureAwait(false);
Expand Down
6 changes: 3 additions & 3 deletions Source/StrongGrid/Models/BccSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace StrongGrid.Models
{
Expand All @@ -13,7 +13,7 @@ public class BccSettings
/// <value>
/// <c>true</c> if enabled; otherwise, <c>false</c>.
/// </value>
[JsonProperty("enable", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("enable")]
public bool Enabled { get; set; }

/// <summary>
Expand All @@ -22,7 +22,7 @@ public class BccSettings
/// <value>
/// The email address.
/// </value>
[JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("email")]
public string EmailAddress { get; set; }
}
}
11 changes: 1 addition & 10 deletions Source/StrongGrid/Models/MailSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace StrongGrid.Models
{
Expand All @@ -7,15 +7,6 @@ namespace StrongGrid.Models
/// </summary>
public class MailSettings
{
/// <summary>
/// Gets or sets the BCC.
/// </summary>
/// <value>
/// The BCC.
/// </value>
[JsonProperty("bcc", NullValueHandling = NullValueHandling.Ignore)]
public BccSettings Bcc { get; set; }

/// <summary>
/// Gets or sets the bypass list management.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Source/StrongGrid/Resources/ISettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using StrongGrid.Models;
using StrongGrid.Utilities;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -197,6 +198,7 @@ public interface ISettings
/// <returns>
/// The <see cref="EmailAddressSetting" />.
/// </returns>
[Obsolete("As of august 2020, SendGrid has retired BCC mail settings.")]
Task<EmailAddressSetting> GetBccMailSettingsAsync(string onBehalfOf = null, CancellationToken cancellationToken = default);

/// <summary>
Expand All @@ -209,6 +211,7 @@ public interface ISettings
/// <returns>
/// The <see cref="EmailAddressSetting" />.
/// </returns>
[Obsolete("As of august 2020, SendGrid has retired BCC mail settings.")]
Task<EmailAddressSetting> UpdateBccMailSettingsAsync(bool enabled, string email, string onBehalfOf = null, CancellationToken cancellationToken = default);

/// <summary>
Expand Down
6 changes: 0 additions & 6 deletions Source/StrongGrid/Resources/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ public async Task<string> SendAsync(
numberOfRecipients += personalizationsCopy.Sum(p => p.Bcc?.Count(r => r != null) ?? 0);
if (numberOfRecipients >= 1000) throw new ArgumentOutOfRangeException(nameof(numberOfRecipients), numberOfRecipients, "The total number of recipients must be less than 1000");

// SendGrid throws an unhelpful error when the Bcc email address is an empty string
if (mailSettings?.Bcc != null && string.IsNullOrWhiteSpace(mailSettings.Bcc.EmailAddress))
{
mailSettings.Bcc.EmailAddress = null;
}

var isDynamicTemplate = Template.IsDynamic(templateId);
var personalizationConverter = new MailPersonalizationConverter(isDynamicTemplate);

Expand Down
3 changes: 3 additions & 0 deletions Source/StrongGrid/Resources/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Pathoschild.Http.Client;
using StrongGrid.Models;
using StrongGrid.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -369,6 +370,7 @@ public Task<GlobalSetting[]> GetAllMailSettingsAsync(int limit = 25, int offset
/// <returns>
/// The <see cref="EmailAddressSetting" />.
/// </returns>
[Obsolete("As of august 2020, SendGrid has retired BCC mail settings.")]
public Task<EmailAddressSetting> GetBccMailSettingsAsync(string onBehalfOf = null, CancellationToken cancellationToken = default)
{
return _client
Expand All @@ -388,6 +390,7 @@ public Task<EmailAddressSetting> GetBccMailSettingsAsync(string onBehalfOf = nul
/// <returns>
/// The <see cref="EmailAddressSetting" />.
/// </returns>
[Obsolete("As of august 2020, SendGrid has retired BCC mail settings.")]
public Task<EmailAddressSetting> UpdateBccMailSettingsAsync(bool enabled, string email, string onBehalfOf = null, CancellationToken cancellationToken = default)
{
var bccMailSettings = new EmailAddressSetting
Expand Down

0 comments on commit eda7364

Please sign in to comment.