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.

24 lines
812 B

  1. import requests
  2. import simplejson
  3. from openerp import models, api
  4. import logging
  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 res.status_code == 200 and simplejson.loads(res.text)["domain"]["state"] == "active":
  19. self.sudo().set_param('mailgun.verified', '1')