From 18e9d319fdf7354226d12f43901a986921334509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 7 Mar 2014 16:33:15 +0100 Subject: [PATCH] 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 --- lib/email/sender.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/email/sender.rb b/lib/email/sender.rb index abdd35023..c972439eb 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -9,6 +9,8 @@ require_dependency 'email/renderer' require 'uri' +SMTP_CLIENT_ERRORS = [Net::SMTPFatalError, Net::SMTPSyntaxError] + module Email class Sender @@ -77,12 +79,15 @@ module Email @message.header['X-Discourse-Post-Id'] = 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 email_log.save! email_log - end def to_address