##// END OF EJS Templates
mailing: switched from homebrew lib to pyramid_mailer with python3 compatability
marcink -
r3113:d517813a default
parent child Browse files
Show More
@@ -26,8 +26,6 b' debug = true'
26 #smtp_port =
26 #smtp_port =
27 #smtp_use_tls = false
27 #smtp_use_tls = false
28 #smtp_use_ssl = true
28 #smtp_use_ssl = true
29 ## Specify available auth parameters here (e.g. LOGIN PLAIN CRAM-MD5, etc.)
30 #smtp_auth =
31
29
32 [server:main]
30 [server:main]
33 ## COMMON ##
31 ## COMMON ##
@@ -26,8 +26,6 b' debug = true'
26 #smtp_port =
26 #smtp_port =
27 #smtp_use_tls = false
27 #smtp_use_tls = false
28 #smtp_use_ssl = true
28 #smtp_use_ssl = true
29 ## Specify available auth parameters here (e.g. LOGIN PLAIN CRAM-MD5, etc.)
30 #smtp_auth =
31
29
32 [server:main]
30 [server:main]
33 ## COMMON ##
31 ## COMMON ##
@@ -19,9 +19,7 b' Once configured you can check the settin'
19 ## Additionally these settings will be used by the RhodeCode mailing system ##
19 ## Additionally these settings will be used by the RhodeCode mailing system ##
20 ################################################################################
20 ################################################################################
21 #email_to = admin@localhost
21 #email_to = admin@localhost
22 #error_email_from = paste_error@localhost
23 #app_email_from = rhodecode-noreply@localhost
22 #app_email_from = rhodecode-noreply@localhost
24 #error_message =
25 #email_prefix = [RhodeCode]
23 #email_prefix = [RhodeCode]
26
24
27 #smtp_server = mail.server.com
25 #smtp_server = mail.server.com
@@ -30,5 +28,3 b' Once configured you can check the settin'
30 #smtp_port =
28 #smtp_port =
31 #smtp_use_tls = false
29 #smtp_use_tls = false
32 #smtp_use_ssl = true
30 #smtp_use_ssl = true
33 ## Specify available auth parameters here (e.g. LOGIN PLAIN CRAM-MD5, etc.)
34 #smtp_auth =
@@ -1368,6 +1368,22 b' self: super: {'
1368 license = [ { fullName = "Repoze Public License"; } { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1368 license = [ { fullName = "Repoze Public License"; } { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1369 };
1369 };
1370 };
1370 };
1371 "pyramid-mailer" = super.buildPythonPackage {
1372 name = "pyramid-mailer-0.15.1";
1373 doCheck = false;
1374 propagatedBuildInputs = [
1375 self."pyramid"
1376 self."repoze.sendmail"
1377 self."transaction"
1378 ];
1379 src = fetchurl {
1380 url = "https://files.pythonhosted.org/packages/a0/f2/6febf5459dff4d7e653314d575469ad2e11b9d2af2c3606360e1c67202f2/pyramid_mailer-0.15.1.tar.gz";
1381 sha256 = "16vg8jb203jgb7b0hd6wllfqvp542qh2ry1gjai2m6qpv5agy2pc";
1382 };
1383 meta = {
1384 license = [ pkgs.lib.licenses.bsdOriginal ];
1385 };
1386 };
1371 "pyramid-mako" = super.buildPythonPackage {
1387 "pyramid-mako" = super.buildPythonPackage {
1372 name = "pyramid-mako-1.0.2";
1388 name = "pyramid-mako-1.0.2";
1373 doCheck = false;
1389 doCheck = false;
@@ -1596,6 +1612,22 b' self: super: {'
1596 license = [ { fullName = "Repoze Public License"; } { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1612 license = [ { fullName = "Repoze Public License"; } { fullName = "BSD-derived (http://www.repoze.org/LICENSE.txt)"; } ];
1597 };
1613 };
1598 };
1614 };
1615 "repoze.sendmail" = super.buildPythonPackage {
1616 name = "repoze.sendmail-4.4.1";
1617 doCheck = false;
1618 propagatedBuildInputs = [
1619 self."setuptools"
1620 self."zope.interface"
1621 self."transaction"
1622 ];
1623 src = fetchurl {
1624 url = "https://files.pythonhosted.org/packages/12/4e/8ef1fd5c42765d712427b9c391419a77bd48877886d2cbc5e9f23c8cad9b/repoze.sendmail-4.4.1.tar.gz";
1625 sha256 = "096ln02jr2afk7ab9j2czxqv2ryqq7m86ah572nqplx52iws73ks";
1626 };
1627 meta = {
1628 license = [ pkgs.lib.licenses.zpl21 ];
1629 };
1630 };
1599 "requests" = super.buildPythonPackage {
1631 "requests" = super.buildPythonPackage {
1600 name = "requests-2.9.1";
1632 name = "requests-2.9.1";
1601 doCheck = false;
1633 doCheck = false;
@@ -1685,6 +1717,7 b' self: super: {'
1685 self."pyramid-jinja2"
1717 self."pyramid-jinja2"
1686 self."pyramid-mako"
1718 self."pyramid-mako"
1687 self."pyramid"
1719 self."pyramid"
1720 self."pyramid-mailer"
1688 self."pysqlite"
1721 self."pysqlite"
1689 self."python-dateutil"
1722 self."python-dateutil"
1690 self."python-ldap"
1723 self."python-ldap"
@@ -1970,6 +2003,20 b' self: super: {'
1970 license = [ pkgs.lib.licenses.bsdOriginal ];
2003 license = [ pkgs.lib.licenses.bsdOriginal ];
1971 };
2004 };
1972 };
2005 };
2006 "transaction" = super.buildPythonPackage {
2007 name = "transaction-2.2.1";
2008 doCheck = false;
2009 propagatedBuildInputs = [
2010 self."zope.interface"
2011 ];
2012 src = fetchurl {
2013 url = "https://files.pythonhosted.org/packages/a6/5e/09da91cb9373c73aae41721e5571c47db72fa9e11b259ca8fd3b01e306e9/transaction-2.2.1.tar.gz";
2014 sha256 = "0ykcfx5mw76z8wwg6a68ahr52q3qa75hky1xx9axbr9pwiq2097j";
2015 };
2016 meta = {
2017 license = [ pkgs.lib.licenses.zpl21 ];
2018 };
2019 };
1973 "translationstring" = super.buildPythonPackage {
2020 "translationstring" = super.buildPythonPackage {
1974 name = "translationstring-1.3";
2021 name = "translationstring-1.3";
1975 doCheck = false;
2022 doCheck = false;
@@ -61,6 +61,7 b' pyramid-debugtoolbar==4.4.0'
61 pyramid-jinja2==2.7
61 pyramid-jinja2==2.7
62 pyramid-mako==1.0.2
62 pyramid-mako==1.0.2
63 pyramid==1.9.2
63 pyramid==1.9.2
64 pyramid_mailer==0.15.1
64 pysqlite==2.8.3
65 pysqlite==2.8.3
65 python-dateutil
66 python-dateutil
66 python-ldap==3.1.0
67 python-ldap==3.1.0
@@ -26,11 +26,13 b' by celery daemon'
26 import os
26 import os
27 import time
27 import time
28
28
29 from pyramid_mailer.mailer import Mailer
30 from pyramid_mailer.message import Message
31
29 import rhodecode
32 import rhodecode
30 from rhodecode.lib import audit_logger
33 from rhodecode.lib import audit_logger
31 from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask
34 from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask
32 from rhodecode.lib.hooks_base import log_create_repository
35 from rhodecode.lib.hooks_base import log_create_repository
33 from rhodecode.lib.rcmail.smtp_mailer import SmtpMailer
34 from rhodecode.lib.utils2 import safe_int, str2bool
36 from rhodecode.lib.utils2 import safe_int, str2bool
35 from rhodecode.model.db import Session, IntegrityError, Repository, User, true
37 from rhodecode.model.db import Session, IntegrityError, Repository, User, true
36
38
@@ -58,7 +60,11 b' def send_email(recipients, subject, body'
58 return False
60 return False
59
61
60 subject = "%s %s" % (email_config.get('email_prefix', ''), subject)
62 subject = "%s %s" % (email_config.get('email_prefix', ''), subject)
61 if not recipients:
63
64 if recipients:
65 if isinstance(recipients, basestring):
66 recipients = recipients.split(',')
67 else:
62 # if recipients are not defined we send to email_config + all admins
68 # if recipients are not defined we send to email_config + all admins
63 admins = []
69 admins = []
64 for u in User.query().filter(User.admin == true()).all():
70 for u in User.query().filter(User.admin == true()).all():
@@ -70,19 +76,44 b' def send_email(recipients, subject, body'
70 recipients += [config_email]
76 recipients += [config_email]
71 recipients += admins
77 recipients += admins
72
78
73 mail_from = email_config.get('app_email_from', 'RhodeCode')
79 # translate our LEGACY config into the one that pyramid_mailer supports
74 user = email_config.get('smtp_username')
80 email_conf = dict(
75 passwd = email_config.get('smtp_password')
81 host=mail_server,
76 mail_port = email_config.get('smtp_port')
82 port=email_config.get('smtp_port'),
77 tls = str2bool(email_config.get('smtp_use_tls'))
83 username=email_config.get('smtp_username'),
78 ssl = str2bool(email_config.get('smtp_use_ssl'))
84 password=email_config.get('smtp_password'),
79 debug = str2bool(email_config.get('debug'))
85
80 smtp_auth = email_config.get('smtp_auth')
86 tls=str2bool(email_config.get('smtp_use_tls')),
87 ssl=str2bool(email_config.get('smtp_use_ssl')),
88
89 # SSL key file
90 # keyfile='',
91
92 # SSL certificate file
93 # certfile='',
94
95 # Location of maildir
96 # queue_path='',
97
98 default_sender=email_config.get('app_email_from', 'RhodeCode'),
99
100 debug=str2bool(email_config.get('smtp_debug')),
101 # /usr/sbin/sendmail Sendmail executable
102 # sendmail_app='',
103
104 # {sendmail_app} -t -i -f {sender} Template for sendmail execution
105 # sendmail_template='',
106 )
81
107
82 try:
108 try:
83 m = SmtpMailer(mail_from, user, passwd, mail_server, smtp_auth,
109 mailer = Mailer(**email_conf)
84 mail_port, ssl, tls, debug=debug)
110
85 m.send(recipients, subject, body, html_body)
111 message = Message(subject=subject,
112 sender=email_conf['default_sender'],
113 recipients=recipients,
114 body=body, html=html_body)
115 mailer.send_immediately(message)
116
86 except Exception:
117 except Exception:
87 log.exception('Mail sending failed')
118 log.exception('Mail sending failed')
88 return False
119 return False
@@ -6,9 +6,7 b''
6 <%
6 <%
7 elems = [
7 elems = [
8 (_('Email prefix'), c.rhodecode_ini.get('email_prefix'), ''),
8 (_('Email prefix'), c.rhodecode_ini.get('email_prefix'), ''),
9 (_('RhodeCode email from'), c.rhodecode_ini.get('app_email_from'), ''),
9 (_('Email from'), c.rhodecode_ini.get('app_email_from'), ''),
10 (_('Error email from'), c.rhodecode_ini.get('error_email_from'), ''),
11 (_('Error email recipients'), c.rhodecode_ini.get('email_to'), ''),
12
10
13 (_('SMTP server'), c.rhodecode_ini.get('smtp_server'), ''),
11 (_('SMTP server'), c.rhodecode_ini.get('smtp_server'), ''),
14 (_('SMTP username'), c.rhodecode_ini.get('smtp_username'), ''),
12 (_('SMTP username'), c.rhodecode_ini.get('smtp_username'), ''),
@@ -17,7 +15,7 b''
17
15
18 (_('SMTP use TLS'), c.rhodecode_ini.get('smtp_use_tls'), ''),
16 (_('SMTP use TLS'), c.rhodecode_ini.get('smtp_use_tls'), ''),
19 (_('SMTP use SSL'), c.rhodecode_ini.get('smtp_use_ssl'), ''),
17 (_('SMTP use SSL'), c.rhodecode_ini.get('smtp_use_ssl'), ''),
20 (_('SMTP auth'), c.rhodecode_ini.get('smtp_auth'), ''),
18
21 ]
19 ]
22 %>
20 %>
23 <dl class="dl-horizontal settings">
21 <dl class="dl-horizontal settings">
@@ -54,7 +52,3 b''
54 ${h.end_form()}
52 ${h.end_form()}
55 </div>
53 </div>
56 </div>
54 </div>
57
58
59
60
@@ -25,21 +25,12 b' debug = true'
25 ## note: using appenlight for error handling doesn't need this to be uncommented
25 ## note: using appenlight for error handling doesn't need this to be uncommented
26 #email_to = admin@localhost
26 #email_to = admin@localhost
27
27
28 ## in case of Application errors, sent an error email form
29 #error_email_from = rhodecode_error@localhost
30
31 ## additional error message to be send in case of server crash
32 #error_message =
33
34
35 #smtp_server = mail.server.com
28 #smtp_server = mail.server.com
36 #smtp_username =
29 #smtp_username =
37 #smtp_password =
30 #smtp_password =
38 #smtp_port =
31 #smtp_port =
39 #smtp_use_tls = false
32 #smtp_use_tls = false
40 #smtp_use_ssl = true
33 #smtp_use_ssl = true
41 ## Specify available auth parameters here (e.g. LOGIN PLAIN CRAM-MD5, etc.)
42 #smtp_auth =
43
34
44 [server:main]
35 [server:main]
45 ## COMMON ##
36 ## COMMON ##
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now