From fdb3ee7772830d8e1bfde4dfba66a6a729bf28dd Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Fri, 24 Jul 2009 01:29:37 +0300 Subject: [PATCH] email_send: feature to place mails in a maildir, instead of smtp At some testing/development scenarios, we may not want to send the mails away, just place them at a dir for inspection. bzr revid: p_christ@hol.gr-20090723222937-8udu15ncqqxiq2ye --- bin/tools/misc.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/tools/misc.py b/bin/tools/misc.py index a8bbe6c9b7e..08ad464d3d3 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -379,6 +379,18 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non def write(self, s): self.logger.notifyChannel('email_send', netsvc.LOG_DEBUG, s) + smtp_server = config['smtp_server'] + if smtp_server.startswith('maildir:/'): + from mailbox import Maildir + maildir_path = smtp_server[8:] + try: + mdir = Maildir(maildir_path,factory=None, create = True) + mdir.add(msg.as_string(True)) + return True + except Exception,e: + netsvc.Logger().notifyChannel('email_send (maildir)', netsvc.LOG_ERROR, e) + return False + try: oldstderr = smtplib.stderr s = smtplib.SMTP() @@ -390,7 +402,7 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non s.set_debuglevel(int(bool(debug))) # 0 or 1 - s.connect(config['smtp_server'], config['smtp_port']) + s.connect(smtp_server, config['smtp_port']) if ssl: s.ehlo() s.starttls()