diff --git a/odoo/addons/base/models/ir_mail_server.py b/odoo/addons/base/models/ir_mail_server.py index 75d7f082196db62ab5ea55eee5ef360f2f3db466..97f100fb94bc9fe51f4dc73b9573cb5d9985d434 100644 --- a/odoo/addons/base/models/ir_mail_server.py +++ b/odoo/addons/base/models/ir_mail_server.py @@ -156,12 +156,37 @@ class IrMailServer(models.Model): smtp = False try: smtp = self.connect(mail_server_id=server.id) + # simulate sending an email from current user's address - without sending it! + email_from, email_to = self.env.user.email, 'noreply@odoo.com' + if not email_from: + raise UserError(_('Please configure an email on the current user to simulate ' + 'sending an email message via this outgoing server')) + # Testing the MAIL FROM step should detect sender filter problems + (code, repl) = smtp.mail(email_from) + if code != 250: + raise UserError(_('The server refused the sender address (%(email_from)s) ' + 'with error %(repl)s') % locals()) + # Testing the RCPT TO step should detect most relaying problems + (code, repl) = smtp.rcpt(email_to) + if code not in (250, 251): + raise UserError(_('The server refused the test recipient (%(email_to)s) ' + 'with error %(repl)s') % locals()) + # Beginning the DATA step should detect some deferred rejections + # Can't use self.data() as it would actually send the mail! + smtp.putcmd("data") + (code, repl) = smtp.getreply() + if code != 354: + raise UserError(_('The server refused the test connection ' + 'with error %(repl)s') % locals()) + except UserError as e: + # let UserErrors (messages) bubble up + raise e except Exception as e: raise UserError(_("Connection Test Failed! Here is what we got instead:\n %s") % ustr(e)) finally: try: if smtp: - smtp.quit() + smtp.close() except Exception: # ignored, just a consequence of the previous exception pass