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.

39 lines
1.3 KiB

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