Browse Source

[ADD] mailgun: automatic domain verification

pull/32/head
Ildar Nasyrov 9 years ago
parent
commit
e3c94a5969
  1. 3
      mailgun/__openerp__.py
  2. 14
      mailgun/data/cron.xml
  3. 13
      mailgun/doc/changelog.rst
  4. 16
      mailgun/models.py

3
mailgun/__openerp__.py

@ -5,8 +5,9 @@
'license': 'LGPL-3', 'license': 'LGPL-3',
'website': "https://twitter.com/nasyrov_ildar", 'website': "https://twitter.com/nasyrov_ildar",
'category': 'Discuss', 'category': 'Discuss',
'version': '1.0.0',
'version': '1.1.0',
'depends': ['mail'], 'depends': ['mail'],
'data': [ 'data': [
'data/cron.xml',
], ],
} }

14
mailgun/data/cron.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="mailgun_domain_verification" model="ir.cron">
<field name="name">Mailgun - domain verification</field>
<field name='interval_number'>10</field>
<field name='interval_type'>minutes</field>
<field name="numbercall">-1</field>
<field name="active">True</field>
<field name="model">ir.config_parameter</field>
<field name="function">mailgun_verify</field>
</record>
</data>
</openerp>

13
mailgun/doc/changelog.rst

@ -0,0 +1,13 @@
Changelog
=========
`1.1.0`
-------
- ADD: automatic domain verification
-------
`1.0.0`
-------
- Init version

16
mailgun/models.py

@ -2,6 +2,7 @@ import requests
import time import time
import dateutil import dateutil
import pytz import pytz
import simplejson
from openerp import models, api from openerp import models, api
@ -19,3 +20,18 @@ class MailThread(models.AbstractModel):
api_key = self.env['ir.config_parameter'].sudo().get_param('mailgun.apikey') api_key = self.env['ir.config_parameter'].sudo().get_param('mailgun.apikey')
res = requests.get(message_url, headers={'Accept': 'message/rfc2822'}, auth=('api', api_key)) res = requests.get(message_url, headers={'Accept': 'message/rfc2822'}, auth=('api', api_key))
self.message_process(False, res.json().get('body-mime')) self.message_process(False, res.json().get('body-mime'))
class IrConfigParameter(models.Model):
_inherit = ['ir.config_parameter']
@api.model
def mailgun_verify(self):
api_key = self.get_param('mailgun.apikey')
mail_domain = self.get_param('mail.catchall.domain')
cron_record = self.env.ref('base.mailgun_domain_verification')
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"]["sate"] == "active":
cron_record.write({'active': False})
Loading…
Cancel
Save