Following the Plone community-managed developer docs about sending e-mail:
try:
host = getToolByName(self, 'MailHost')
return host.send(mail_text)
except SMTPRecipientsRefused:
# Don't disclose email address on failure
raise SMTPRecipientsRefused('Recipient address rejected by server')
…but return host.send(mail_text) always returns None, regardless if the email was sent or not (the email is being sent actually). So, can I assume if None is the result, it was successfull? This doesn’t seen right to me. Any thoughts?
Python has exceptions so does not need to return a status code to indicate a failure. (With C/Unix a return code of 0 indicates success, a boolean true value indicates an error.)
If you need to react to a mail failure in your code, you must include
immediate=Truein the parameters, otherwise the mail will be sent at the transaction boundary and possibly queued. You can then catch an exception using try/except.