diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-10-31 12:17:26 +0100 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-11-05 18:02:32 -0200 |
commit | 9ab17e2bbf61062ce8399ef1c51d2069a0cced31 (patch) | |
tree | 4079dcbd6f4fe5c485595491f4fb874e3898bc1c /service/pixelated/adapter/mail_sender.py | |
parent | 0bfc4824189807c7a8971093910ced527b4e6a29 (diff) |
moving to twisted
Diffstat (limited to 'service/pixelated/adapter/mail_sender.py')
-rw-r--r-- | service/pixelated/adapter/mail_sender.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/service/pixelated/adapter/mail_sender.py b/service/pixelated/adapter/mail_sender.py index 1802a9d5..6fad2b6f 100644 --- a/service/pixelated/adapter/mail_sender.py +++ b/service/pixelated/adapter/mail_sender.py @@ -13,21 +13,26 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -import smtplib +from StringIO import StringIO +from twisted.internet.defer import Deferred +from twisted.mail.smtp import SMTPSenderFactory +from twisted.internet import reactor from pixelated.support.functional import flatten class MailSender(): def __init__(self, account_email_address, smtp_client=None): self.account_email_address = account_email_address - self.smtp_client = smtp_client or smtplib.SMTP('localhost', 4650) def sendmail(self, mail): recipients = flatten([mail.to, mail.cc, mail.bcc]) - self.smtp_client.sendmail( - self.account_email_address, - recipients, - mail.to_smtp_format() - ) + resultDeferred = Deferred() + senderFactory = SMTPSenderFactory( + fromEmail=self.account_email_address, + toEmail=recipients, + file=StringIO(mail.to_smtp_format()), + deferred=resultDeferred) + + return reactor.connectTCP('localhost', 4650, senderFactory) |