MessageId improvements for MailKitSender#324
Open
belidzs wants to merge 2 commits intolukencode:masterfrom
Open
MessageId improvements for MailKitSender#324belidzs wants to merge 2 commits intolukencode:masterfrom
belidzs wants to merge 2 commits intolukencode:masterfrom
Conversation
Use local MessageId as SendResponse.MessageId Use remotely generated MessageId when using Amazon SES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains two changes regarding MailKitSender:
Explanation
Returning local MessageId as part of SendResponse
MailKit generates a local
Message-Idfor each message which is then passed to the remote SMTP service. Currently this field is not returned as part ofSendResponse. This PR changes that.Amazon SES
While the header Message-Id should remain unchanged after its value is first set, Amazon's SES service overwrites it with its own value.
Knowing the value of this field is useful if someone wants to track whether a particular message has been accepted, bounced, complained about, etc.
This PR makes use of the
SmtpClient.MessageSentevent which fires after the message has been accepted. By using the hostname of the SMTP service and leveraging theResponseproperty from theMessageSentEventArgsclass we can determine the final value of Message-Id.Since it cannot be guaranteed that the
MessageSentevent will fire before theISender.SendorISender.SendAsyncmethod is returned, I've used an instance ofManualResetEventSlimto block the thread onWait()until it is signaled. This signal is sent at the end of the MessageSent event (if the client is configured to use SES) or right away if SES is not used.References
Source: https://docs.aws.amazon.com/ses/latest/dg/header-fields.html
Source: https://docs.aws.amazon.com/ses/latest/dg/send-email-concepts-process.html