diff options
| author | P. Christeas <p_christ@hol.gr> | 2009-07-24 01:29:37 +0300 |
|---|---|---|
| committer | P. Christeas <p_christ@hol.gr> | 2009-07-24 01:29:37 +0300 |
| commit | fdb3ee7772830d8e1bfde4dfba66a6a729bf28dd (patch) | |
| tree | 956d7f298426d9026edfe5236963eafd6b10713f /bin/tools/misc.py | |
| parent | 5611c395c48c87305be53c7c0fa00cf5ae7c3698 (diff) | |
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
Diffstat (limited to 'bin/tools/misc.py')
| -rw-r--r-- | bin/tools/misc.py | 14 |
1 files changed, 13 insertions, 1 deletions
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() |
