changeset cbdb59e92439 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=cbdb59e92439
description:
        Add option to send test email with trytond-admin

        issue8983
        review274681002
diffstat:

 CHANGELOG                    |   1 +
 doc/topics/configuration.rst |   2 ++
 trytond/admin.py             |   3 +++
 trytond/commandline.py       |   2 ++
 trytond/sendmail.py          |  10 ++++++++++
 5 files changed, 18 insertions(+), 0 deletions(-)

diffs (81 lines):

diff -r 691ef455b158 -r cbdb59e92439 CHANGELOG
--- a/CHANGELOG Tue Mar 17 23:33:10 2020 +0100
+++ b/CHANGELOG Wed Mar 18 12:36:48 2020 +0100
@@ -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 -r 691ef455b158 -r cbdb59e92439 doc/topics/configuration.rst
--- a/doc/topics/configuration.rst      Tue Mar 17 23:33:10 2020 +0100
+++ b/doc/topics/configuration.rst      Wed Mar 18 12:36:48 2020 +0100
@@ -237,6 +237,8 @@
 email
 -----
 
+.. note:: Email settings can be tested with the `trytond-admin` command
+
 uri
 ~~~
 
diff -r 691ef455b158 -r cbdb59e92439 trytond/admin.py
--- a/trytond/admin.py  Tue Mar 17 23:33:10 2020 +0100
+++ b/trytond/admin.py  Wed Mar 18 12:36:48 2020 +0100
@@ -11,6 +11,7 @@
 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 @@
             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 -r 691ef455b158 -r cbdb59e92439 trytond/commandline.py
--- a/trytond/commandline.py    Tue Mar 17 23:33:10 2020 +0100
+++ b/trytond/commandline.py    Wed Mar 18 12:36:48 2020 +0100
@@ -75,6 +75,8 @@
         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 -r 691ef455b158 -r cbdb59e92439 trytond/sendmail.py
--- a/trytond/sendmail.py       Tue Mar 17 23:33:10 2020 +0100
+++ b/trytond/sendmail.py       Wed Mar 18 12:36:48 2020 +0100
@@ -4,6 +4,7 @@
 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 @@
         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')

Reply via email to