matrix-org / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://matrix-org.github.io/synapse
Apache License 2.0
11.82k stars 2.13k forks source link

Enable sending emails notifications fail #3619

Closed vandsten closed 5 years ago

vandsten commented 6 years ago

Description

When we want to enable emails notifications fail.

Steps to reproduce

We have modified file configuration /etc/matrix-synapse/homeserver.yaml and add then next block configuration:

email:
   enable_notifs: true
   smtp_host: "smtp.example.com"
   smtp_port: 587
   smtp_user: "mailaccount"
   smtp_pass: "passswordaccount"
   require_transport_security: True
   notif_from: "Your Friendly %(app)s Home Server <soporte_notificaciones_matrix@example.com>"
   app_name: Matrix
   template_dir: res/templates
   notif_template_html: notif_mail.html
   notif_template_text: notif_mail.txt
   notif_for_new_users: True
   riot_base_url: "https://riot.example.com"

We have creadted /etc/matrix-synpase/res directory and get files from: https://github.com/matrix-org/synapse/tree/master/res/templates

Then we restart service with "systemctl restart matrix-synapse" but no start synapse service. Log output is next (/var/log/matrix-synapse/homeserver.log):

2018-07-27 12:53:19,612 - synapse.app.homeserver - 343 - INFO - None- Preparing database: psycopg2...
2018-07-27 12:53:19,627 - synapse.storage.prepare_database - 223 - INFO - None- Upgrading schema to v50
2018-07-27 12:53:19,631 - synapse.app.homeserver - 361 - INFO - None- Database prepared in psycopg2.
2018-07-27 12:53:19,631 - synapse.server - 189 - INFO - None- Setting up.
2018-07-27 12:53:19,684 - synapse.storage.event_push_actions - 469 - INFO - None- Searching for stream ordering 1 month ago
2018-07-27 12:53:19,694 - synapse.storage.event_push_actions - 475 - INFO - None- Found stream ordering 1 month ago: it's 2
2018-07-27 12:53:19,694 - synapse.storage.event_push_actions - 477 - INFO - None- Searching for stream ordering 1 day ago
2018-07-27 12:53:19,702 - synapse.storage.event_push_actions - 483 - INFO - None- Found stream ordering 1 day ago: it's 1682
2018-07-27 12:53:19,706 - synapse.server - 191 - INFO - None- Finished setting up.
2018-07-27 12:53:19,708 - synapse.handlers.auth - 79 - INFO - None- Extra password_providers: [<ldap_auth_provider.LdapAuthProvider object at 0x7f992e93ae90>]
2018-07-27 12:53:19,709 - synapse.push.pusher - 43 - INFO - None- email enable notifs: True
2018-07-27 12:53:19,710 - synapse.push.mailer - 528 - INFO - None- loading jinja2
2018-07-27 12:53:19,710 - twisted - 131 - ERROR - - Traceback (most recent call last):
2018-07-27 12:53:19,711 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
2018-07-27 12:53:19,711 - twisted - 131 - ERROR - -     "__main__", fname, loader, pkg_name)
2018-07-27 12:53:19,711 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
2018-07-27 12:53:19,712 - twisted - 131 - ERROR - -     exec code in run_globals
2018-07-27 12:53:19,712 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/app/homeserver.py", line 540, in <module>
2018-07-27 12:53:19,713 - twisted - 131 - ERROR - -     main()
2018-07-27 12:53:19,713 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/app/homeserver.py", line 535, in main
2018-07-27 12:53:19,713 - twisted - 131 - ERROR - -     hs = setup(sys.argv[1:])
2018-07-27 12:53:19,714 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/app/homeserver.py", line 364, in setup
2018-07-27 12:53:19,714 - twisted - 131 - ERROR - -     hs.start_listening()
2018-07-27 12:53:19,714 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/app/homeserver.py", line 251, in start_listening
2018-07-27 12:53:19,715 - twisted - 131 - ERROR - -     self._listener_http(config, listener)
2018-07-27 12:53:19,715 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/app/homeserver.py", line 121, in _listener_http
2018-07-27 12:53:19,715 - twisted - 131 - ERROR - -     config, name, res.get("compress", False),
2018-07-27 12:53:19,715 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/app/homeserver.py", line 181, in _configure_named_resource
2018-07-27 12:53:19,716 - twisted - 131 - ERROR - -     client_resource = ClientRestResource(self)
2018-07-27 12:53:19,716 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/rest/__init__.py", line 51, in __init__
2018-07-27 12:53:19,716 - twisted - 131 - ERROR - -     self.register_servlets(self, hs)
2018-07-27 12:53:19,717 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/rest/__init__.py", line 58, in register_servlets
2018-07-27 12:53:19,717 - twisted - 131 - ERROR - -     room.register_servlets(hs, client_resource)
2018-07-27 12:53:19,717 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/rest/client/v1/room.py", line 824, in register_servlets
2018-07-27 12:53:19,718 - twisted - 131 - ERROR - -     RoomStateEventRestServlet(hs).register(http_server)
2018-07-27 12:53:19,718 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/rest/client/v1/room.py", line 90, in __init__
2018-07-27 12:53:19,718 - twisted - 131 - ERROR - -     self.handlers = hs.get_handlers()
2018-07-27 12:53:19,719 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/server.py", line 460, in _get
2018-07-27 12:53:19,719 - twisted - 131 - ERROR - -     dep = builder()
2018-07-27 12:53:19,719 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/server.py", line 231, in build_handlers
2018-07-27 12:53:19,720 - twisted - 131 - ERROR - -     return Handlers(self)
2018-07-27 12:53:19,720 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/handlers/__init__.py", line 48, in __init__
2018-07-27 12:53:19,720 - twisted - 131 - ERROR - -     self.federation_handler = FederationHandler(hs)
2018-07-27 12:53:19,720 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/handlers/federation.py", line 85, in __init__
2018-07-27 12:53:19,721 - twisted - 131 - ERROR - -     self.pusher_pool = hs.get_pusherpool()
2018-07-27 12:53:19,721 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/server.py", line 460, in _get
2018-07-27 12:53:19,721 - twisted - 131 - ERROR - -     dep = builder()
2018-07-27 12:53:19,722 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/server.py", line 331, in build_pusherpool
2018-07-27 12:53:19,722 - twisted - 131 - ERROR - -     return PusherPool(self)
2018-07-27 12:53:19,722 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/push/pusherpool.py", line 30, in __init__
2018-07-27 12:53:19,723 - twisted - 131 - ERROR - -     self.pusher_factory = PusherFactory(_hs)
2018-07-27 12:53:19,723 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/push/pusher.py", line 47, in __init__
2018-07-27 12:53:19,723 - twisted - 131 - ERROR - -     templates = load_jinja2_templates(hs.config)
2018-07-27 12:53:19,723 - twisted - 131 - ERROR - -   File "/usr/lib/python2.7/dist-packages/synapse/push/mailer.py", line 536, in load_jinja2_templates
2018-07-27 12:53:19,724 - twisted - 131 - ERROR - -     config.email_notif_template_html
2018-07-27 12:53:19,724 - twisted - 131 - ERROR - -   File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 830, in get_template
2018-07-27 12:53:19,724 - twisted - 131 - ERROR - -     return self._load_template(name, self.make_globals(globals))
2018-07-27 12:53:19,725 - twisted - 131 - ERROR - -   File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 804, in _load_template
2018-07-27 12:53:19,725 - twisted - 131 - ERROR - -     template = self.loader.load(self, name, globals)
2018-07-27 12:53:19,725 - twisted - 131 - ERROR - -   File "/usr/local/lib/python2.7/dist-packages/jinja2/loaders.py", line 113, in load
2018-07-27 12:53:19,726 - twisted - 131 - ERROR - -     source, filename, uptodate = self.get_source(environment, name)
2018-07-27 12:53:19,726 - twisted - 131 - ERROR - -   File "/usr/local/lib/python2.7/dist-packages/jinja2/loaders.py", line 187, in get_source
2018-07-27 12:53:19,726 - twisted - 131 - ERROR - -     raise TemplateNotFound(template)
2018-07-27 12:53:19,727 - twisted - 131 - ERROR - - jinja2.exceptions.TemplateNotFound: notif_mail.html

We see that notif_mail.html is not found but it is in directory /etc/matrix-synapse/res/

Version information

akanouras commented 6 years ago

For future reference:

It actually looks for template_dir in /var/lib/matrix-synapse/.

In your case, you could set it like this: template_dir: /etc/matrix-synapse/res/templates