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.

25 lines
836 B

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