Commit 0180b8b0 authored by Arthur Lutz's avatar Arthur Lutz
Browse files

[cubicweb/cwconfig] authenticated SMTP outgoing email

parent 94588f6e828d
...@@ -855,6 +855,16 @@ class CubicWebConfiguration(CubicWebNoAppConfiguration): ...@@ -855,6 +855,16 @@ class CubicWebConfiguration(CubicWebNoAppConfiguration):
'help': 'listening port of the SMTP mail server', 'help': 'listening port of the SMTP mail server',
'group': 'email', 'level': 1, 'group': 'email', 'level': 1,
}), }),
('smtp-username',
{'default': '',
'help': 'username for SMTP mail server if auth is required',
'group': 'email', 'level': 2,
}),
('smtp-password',
{'default': '',
'help': 'password for SMTP mail server if auth is required',
'group': 'email', 'level': 2,
}),
('sender-name', ('sender-name',
{'type' : 'string', {'type' : 'string',
'default': Method('default_instance_id'), 'default': Method('default_instance_id'),
...@@ -1238,12 +1248,15 @@ the repository', ...@@ -1238,12 +1248,15 @@ the repository',
if connection to the smtp server failed, else True. if connection to the smtp server failed, else True.
""" """
server, port = self['smtp-host'], self['smtp-port'] server, port = self['smtp-host'], self['smtp-port']
smtp_user, smtp_password = self['smtp-user'], self['smtp-password']
if fromaddr is None: if fromaddr is None:
fromaddr = '%s <%s>' % (self['sender-name'], self['sender-addr']) fromaddr = '%s <%s>' % (self['sender-name'], self['sender-addr'])
SMTP_LOCK.acquire() SMTP_LOCK.acquire()
try: try:
try: try:
smtp = SMTP(server, port) smtp = SMTP(server, port)
if smtp_user and smtp_password:
smtp.login(smtp_user, smtp_password)
except Exception as ex: except Exception as ex:
self.exception("can't connect to smtp server %s:%s (%s)", self.exception("can't connect to smtp server %s:%s (%s)",
server, port, ex) server, port, ex)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment