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.

43 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. import logging
  3. import requests
  4. import simplejson
  5. from openerp import api, models
  6. _logger = logging.getLogger(__name__)
  7. class MailThread(models.AbstractModel):
  8. _inherit = "mail.thread"
  9. @api.model
  10. def mailgun_fetch_message(self, message_url):
  11. api_key = self.env["ir.config_parameter"].sudo().get_param("mailgun.apikey")
  12. res = requests.get(
  13. message_url,
  14. headers={"Accept": "message/rfc2822"},
  15. auth=("api", api_key),
  16. verify=False,
  17. )
  18. self.message_process(False, res.json().get("body-mime"))
  19. class IrConfigParameter(models.Model):
  20. _inherit = ["ir.config_parameter"]
  21. @api.model
  22. def mailgun_verify(self):
  23. verified = self.get_param("mailgun.verified")
  24. if verified:
  25. return
  26. api_key = self.get_param("mailgun.apikey")
  27. mail_domain = self.get_param("mail.catchall.domain")
  28. if api_key and mail_domain:
  29. url = "https://api.mailgun.net/v3/domains/%s/verify" % mail_domain
  30. res = requests.put(url, auth=("api", api_key))
  31. if (
  32. res.status_code == 200
  33. and simplejson.loads(res.text)["domain"]["state"] == "active"
  34. ):
  35. self.set_param("mailgun.verified", "1")