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.

36 lines
1.2 KiB

  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 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(message_url, headers={'Accept': 'message/rfc2822'}, auth=('api', api_key), verify=False)
  13. self.message_process(False, res.json().get('body-mime'))
  14. class IrConfigParameter(models.Model):
  15. _inherit = ['ir.config_parameter']
  16. @api.model
  17. def mailgun_verify(self):
  18. verified = self.get_param('mailgun.verified')
  19. if verified:
  20. return
  21. api_key = self.get_param('mailgun.apikey')
  22. mail_domain = self.get_param('mail.catchall.domain')
  23. if api_key and mail_domain:
  24. url = "https://api.mailgun.net/v3/domains/%s/verify" % mail_domain
  25. res = requests.put(url, auth=("api", api_key))
  26. if res.status_code == 200 and simplejson.loads(res.text)["domain"]["state"] == "active":
  27. self.set_param('mailgun.verified', '1')