Add option to send test email with trytond-admin
issue8983 review274681002
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -237,6 +237,8 @@ The path to the certificate.
|
||||
email
|
||||
-----
|
||||
|
||||
.. note:: Email settings can be tested with the `trytond-admin` command
|
||||
|
||||
uri
|
||||
~~~
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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='+',
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user