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.

33 lines
907 B

  1. import logging
  2. import requests
  3. from odoo import api, models
  4. try:
  5. import simplejson as json
  6. except ImportError:
  7. import json
  8. _logger = logging.getLogger(__name__)
  9. class IrConfigParameter(models.Model):
  10. _inherit = ["ir.config_parameter"]
  11. @api.model
  12. def mailgun_verify(self):
  13. verified = self.sudo().get_param("mailgun.verified")
  14. if verified:
  15. return
  16. api_key = self.sudo().get_param("mailgun.apikey")
  17. mail_domain = self.sudo().get_param("mail.catchall.domain")
  18. if api_key and mail_domain:
  19. url = "https://api.mailgun.net/v3/domains/%s/verify" % mail_domain
  20. res = requests.put(url, auth=("api", api_key))
  21. if (
  22. res.status_code == 200
  23. and json.loads(res.text)["domain"]["state"] == "active"
  24. ):
  25. self.sudo().set_param("mailgun.verified", "1")