new parameter to pipe mails to an external process
This commit is contained in:
parent
6de583c4ca
commit
61280d313e
1 changed files with 18 additions and 5 deletions
|
|
@ -27,6 +27,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import asyncore
|
import asyncore
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from weboob.core import Weboob, CallErrors
|
from weboob.core import Weboob, CallErrors
|
||||||
from weboob.core.scheduler import Scheduler
|
from weboob.core.scheduler import Scheduler
|
||||||
|
|
@ -83,6 +84,7 @@ class Monboob(ReplApplication):
|
||||||
'domain': 'weboob.example.org',
|
'domain': 'weboob.example.org',
|
||||||
'recipient': 'weboob@example.org',
|
'recipient': 'weboob@example.org',
|
||||||
'smtp': 'localhost',
|
'smtp': 'localhost',
|
||||||
|
'pipe': '',
|
||||||
'html': 0}
|
'html': 0}
|
||||||
CAPS = ICapMessages
|
CAPS = ICapMessages
|
||||||
DISABLE_REPL = True
|
DISABLE_REPL = True
|
||||||
|
|
@ -285,10 +287,21 @@ class Monboob(ReplApplication):
|
||||||
if reply_id:
|
if reply_id:
|
||||||
msg['In-Reply-To'] = reply_id
|
msg['In-Reply-To'] = reply_id
|
||||||
|
|
||||||
# Send the message via SMTP to localhost:25
|
self.logger.info('Send mail from <%s> to <%s>' % (sender, recipient))
|
||||||
smtp = SMTP(self.config.get('smtp'))
|
if len(self.config.get('pipe')) > 0:
|
||||||
print 'Send mail from <%s> to <%s>' % (sender, recipient)
|
p = subprocess.Popen(self.config.get('pipe'),
|
||||||
smtp.sendmail(sender, recipient, msg.as_string())
|
shell=True,
|
||||||
smtp.quit()
|
stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT)
|
||||||
|
p.stdin.write(msg.as_string())
|
||||||
|
p.stdin.close()
|
||||||
|
if p.wait() != 0:
|
||||||
|
self.logger.error('Unable to deliver mail: %s' % p.stdout.read().strip())
|
||||||
|
else:
|
||||||
|
# Send the message via SMTP to localhost:25
|
||||||
|
smtp = SMTP(self.config.get('smtp'))
|
||||||
|
smtp.sendmail(sender, recipient, msg.as_string())
|
||||||
|
smtp.quit()
|
||||||
|
|
||||||
return msg['Message-Id']
|
return msg['Message-Id']
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue