Add option to send test email with trytond-admin

issue8983
review274681002
This commit is contained in:
Sergi Almacellas Abellana
2020-03-18 12:36:48 +01:00
parent e806ec55a8
commit 6ac6424d88
5 changed files with 18 additions and 0 deletions
+1
View File
@@ -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
+2
View File
@@ -237,6 +237,8 @@ The path to the certificate.
email
-----
.. note:: Email settings can be tested with the `trytond-admin` command
uri
~~~
+3
View File
@@ -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()
+2
View File
@@ -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='+',
+10
View File
@@ -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')