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

import requests
import simplejson
from openerp import models, api
import logging
_logger = logging.getLogger(__name__)
class IrConfigParameter(models.Model):
_inherit = ['ir.config_parameter']
@api.model
def mailgun_verify(self):
verified = self.sudo().get_param('mailgun.verified')
if verified:
return
api_key = self.sudo().get_param('mailgun.apikey')
mail_domain = self.sudo().get_param('mail.catchall.domain')
if api_key and mail_domain:
url = "https://api.mailgun.net/v3/domains/%s/verify" % mail_domain
res = requests.put(url, auth=("api", api_key))
if res.status_code == 200 and simplejson.loads(res.text)["domain"]["state"] == "active":
self.sudo().set_param('mailgun.verified', '1')