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.

34 lines
1.2 KiB

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