BUGFIX: catch STMP client errors in email sending background job

Will log the exception message in the skipped reason instead of keeping
the job in the queue whenever the email address is invalid
This commit is contained in:
Régis Hanol 2014-03-07 16:33:15 +01:00
parent b81f77541c
commit 18e9d319fd

View File

@ -9,6 +9,8 @@
require_dependency 'email/renderer' require_dependency 'email/renderer'
require 'uri' require 'uri'
SMTP_CLIENT_ERRORS = [Net::SMTPFatalError, Net::SMTPSyntaxError]
module Email module Email
class Sender class Sender
@ -77,12 +79,15 @@ module Email
@message.header['X-Discourse-Post-Id'] = nil @message.header['X-Discourse-Post-Id'] = nil
@message.header['X-Discourse-Reply-Key'] = nil @message.header['X-Discourse-Reply-Key'] = nil
@message.deliver begin
@message.deliver
rescue SMTP_CLIENT_ERRORS => e
return skip(e.message)
end
# Save and return the email log # Save and return the email log
email_log.save! email_log.save!
email_log email_log
end end
def to_address def to_address