diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-11-03 17:12:15 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-11-03 17:13:56 +0100 |
commit | af7631369c96d3da54abb4e1cab44ea61151c481 (patch) | |
tree | d08187e30b2d49df722eaf97c6cf5a5c0540d831 /service/pixelated/adapter | |
parent | 5c3468304f13fa0fe279a6e04fb90432d6737345 (diff) |
Add new MailSender based on OutgoingMail
- Issue #499
- No longer needs local smtp port
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r-- | service/pixelated/adapter/services/mail_sender.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/service/pixelated/adapter/services/mail_sender.py b/service/pixelated/adapter/services/mail_sender.py index 9c3ea3bb..1befd1cc 100644 --- a/service/pixelated/adapter/services/mail_sender.py +++ b/service/pixelated/adapter/services/mail_sender.py @@ -15,10 +15,11 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from StringIO import StringIO from email.utils import parseaddr +from leap.mail.outgoing.service import OutgoingMail from twisted.internet.defer import Deferred, fail from twisted.mail.smtp import SMTPSenderFactory -from twisted.internet import reactor +from twisted.internet import reactor, defer from pixelated.support.functional import flatten @@ -27,6 +28,29 @@ class SMTPDownException(Exception): Exception.__init__(self, "Couldn't send mail now, try again later.") +class MailSender(object): + + def __init__(self, account_email_address, keymanager, cert_path, remote_smtp_host, remote_smtp_port): + self._from = account_email_address + self._keymanager = keymanager + self._cert_path = cert_path + self._remote_smtp_host = remote_smtp_host + self._remote_smtp_port = remote_smtp_port + + def sendmail(self, mail): + recipients = flatten([mail.to, mail.cc, mail.bcc]) + outgoing_mail = self._create_outgoing_mail() + deferreds = [] + + for recipient in recipients: + deferreds.append(outgoing_mail.send_message(mail.to_smtp_format(), recipient)) + + return defer.gatherResults(deferreds) + + def _create_outgoing_mail(self): + return OutgoingMail(self._from, self._keymanager, self._cert_path, self._cert_path, self._remote_smtp_host, self._remote_smtp_port) + + class LocalSmtpMailSender(object): def __init__(self, account_email_address, smtp): |