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.

27 lines
860 B

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