- Notifications
You must be signed in to change notification settings - Fork914
fix: correctly close SMTP message and await response#14495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Signed-off-by: Danny Kopping <danny@coder.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍 Nice catch!
return &smtp.SMTPError{Code: 501, EnhancedCode: smtp.EnhancedCode{5, 5, 4}, Message: "Rejected!"} | ||
}, | ||
expectedErr: "SMTP error 501: Rejected!", | ||
retryable: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Isn't this error non-retryable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Not apriori; it could be a temporary failure.
if s.backend.cfg.FailOnDataFn != nil { | ||
return s.backend.cfg.FailOnDataFn() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
At some point in the future, would it make sense to test with something likemocktools/go-smtp-mock
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I evaluated it, but it does not support authentication.
c90be9b
intomainUh oh!
There was an error while loading.Please reload this page.
We originally took heavy inspiration fromAlertmanager's SMTP dispatch functionality due to the number of options we need to support.
In their dispatch code, they defer the call to
message.Close
but in fact this is necessary to complete the SMTP submission and await any errors; we do the same in our code.NOTE: We use
emersion/go-smtp
as our SMTP library while Alertmanager usesnet/smtp
, but the former extends the latter, so the code that follows is effectively the same.We cannot defer a call to
Close
because we depend on the error which is returned to determine if the message was successfully sent or not.This line checks if the response was successful (docs); if not, we need to fail this dispatch and mark it for retry.
I discovered this bug by incorrectly configuring
CODER_NOTIFICATIONS_EMAIL_FROM
as my@coder.com
address (which is backed by GSuite) and testing a dispatch via an outlook.com SMTP server. The server was rejecting the message with554 5.2.252 SendAsDenied; <redacted>@outlook.com not allowed to send as <redacted>@coder.com
, but the message was being marked successful, because we were not waiting for the actual outcome of the mail dispatch.This has quite worrying implications for Alertmanager, and I plan to raise a PR in that repo too to address this.