You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

  1. # Copyright 2019 Tecnativa - Jairo Llopis
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo.http import request, route
  4. from odoo.addons.website_mass_mailing.controllers import main
  5. class MassMailController(main.MassMailController):
  6. @route()
  7. def subscribe(self, list_id, email, **post):
  8. """Send welcome email to subscribers."""
  9. result = super().subscribe(list_id, email, **post)
  10. list_ = request.env["mail.mass_mailing.list"] \
  11. .sudo().browse(int(list_id))
  12. template = list_.welcome_mail_template_id
  13. if not template:
  14. return result
  15. # Welcome new subscribers
  16. contact = request.env["mail.mass_mailing.contact"].sudo().search([
  17. ('list_ids', 'in', list_.ids),
  18. ('email', '=', email),
  19. ("opt_out", "=", False),
  20. ], limit=1)
  21. template.with_context(list_name=list_.name).send_mail(
  22. contact.id,
  23. # Must send now to use context
  24. force_send=True,
  25. # If we cannot notify, the visitor shouldn't be bothered
  26. raise_exception=False,
  27. )
  28. return result