MessageId improvements for MailKitSender #324
Open
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-Id
for 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.MessageSent
event which fires after the message has been accepted. By using the hostname of the SMTP service and leveraging theResponse
property from theMessageSentEventArgs
class we can determine the final value of Message-Id.Since it cannot be guaranteed that the
MessageSent
event will fire before theISender.Send
orISender.SendAsync
method is returned, I've used an instance ofManualResetEventSlim
to 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