Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
/ ServerCommon Public archive

Don't attempt to send emails if they have no recipients #222

Merged
merged 8 commits into from
Nov 8, 2018

Conversation

scottbommarito
Copy link
Contributor

NuGet/NuGetGallery#6632

EmailRecipients.None is being compared to by reference, which always fails because it is unused outside of this check.

@scottbommarito scottbommarito changed the title Don't attempt to send emails asynchronously if they have no recipients Don't attempt to send emails if they have no recipients Nov 7, 2018
{
// Optimization: no need to construct message body when no recipients.
_logger.LogInformation("Message has no recipients. Cannot send.");
Copy link
Contributor

@loic-sharma loic-sharma Nov 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot send [](start = 67, length = 11)

Cannot send. could be confused as an error. What do you think of a message like Skipping message as it has no recipients?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split it into two log messages.

Cannot create message to send as it has no recipients. in this function
Skipping enqueueing message because it is null or has no recipients. in EnqueueMessageAsync

@@ -27,6 +32,9 @@ public AsynchronousEmailMessageService(IEmailMessageEnqueuer emailMessageEnqueue
throw new ArgumentNullException(nameof(emailBuilder));
}

_logger.LogInformation("Sending message with CopySender {CopySender} and DiscloseSenderAddress {DiscloseSenderAddress}",
copySender, discloseSenderAddress);

var message = CreateMessage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateMessage [](start = 26, length = 13)

It's not clear here that CreateMessage may return null, which EnqueueMessageAsync handles by doing no work. What do you think of renaming CreateMessage to CreateMessageOrNull, and not calling EnqueueMessageAsync if CreateMessageOrNull returned a null message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to change the structure of the code here that much. I agree it's confusing however.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants