diff --git a/CHANGELOG b/CHANGELOG index 22c947fbd4..cc0ed76fbb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * Set all fields readonly for inactive record * Enable check_access context when checking wizard access (issue9108) +* Add option to send test email with trytond-admin * Add editable on calendar view * Add xalign and yalign to group * Add MultiSelection entry to Dict field diff --git a/doc/topics/configuration.rst b/doc/topics/configuration.rst index 960c7ad383..0eff5f449f 100644 --- a/doc/topics/configuration.rst +++ b/doc/topics/configuration.rst @@ -237,6 +237,8 @@ The path to the certificate. email ----- +.. note:: Email settings can be tested with the `trytond-admin` command + uri ~~~ diff --git a/trytond/admin.py b/trytond/admin.py index 6baaa53e4b..dd233faac5 100644 --- a/trytond/admin.py +++ b/trytond/admin.py @@ -11,6 +11,7 @@ from trytond import backend from trytond.transaction import Transaction from trytond.pool import Pool from trytond.config import config +from trytond.sendmail import send_test_email __all__ = ['run'] logger = logging.getLogger(__name__) @@ -113,6 +114,8 @@ def run(options): admin.save() if options.reset_password: User.reset_password([admin]) + if options.test_email: + send_test_email(options.test_email) if options.hostname is not None: configuration.hostname = options.hostname or None configuration.save() diff --git a/trytond/commandline.py b/trytond/commandline.py index 341326ef7a..deac936c6d 100644 --- a/trytond/commandline.py +++ b/trytond/commandline.py @@ -75,6 +75,8 @@ def get_parser_admin(): action='store_true', help="set the admin password") parser.add_argument("--reset-password", dest='reset_password', action='store_true', help="reset the admin password") + parser.add_argument("--test-email", dest='test_email', + help="Send a test email to the specified address.") parser.add_argument("-m", "--update-modules-list", action="store_true", dest="update_modules_list", help="Update list of tryton modules") parser.add_argument("-l", "--language", dest="languages", nargs='+', diff --git a/trytond/sendmail.py b/trytond/sendmail.py index 57524e7af3..4c04fe5746 100644 --- a/trytond/sendmail.py +++ b/trytond/sendmail.py @@ -4,6 +4,7 @@ import logging import smtplib from email.message import Message from email.utils import formatdate +from email.mime.text import MIMEText from urllib.parse import parse_qs, unquote_plus from .config import config, parse_uri @@ -45,6 +46,15 @@ def sendmail(from_addr, to_addrs, msg, server=None): server.quit() +def send_test_email(to_addrs, server=None): + from_ = config.get('email', 'from') + msg = MIMEText('Success!\nYour email settings work correctly.') + msg['From'] = from_ + msg['To'] = to_addrs + msg['Subject'] = 'Tryton test email' + sendmail(config.get('email', 'from'), to_addrs, msg, server=server) + + def get_smtp_server(uri=None): if uri is None: uri = config.get('email', 'uri')