Browse Source

Merge pull request #32 from iledarn/9.0-mailgun-verify

9.0 mailgun verify
pull/33/merge
Ivan Yelizariev 9 years ago
parent
commit
096ca0a155
  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',
'website': "https://twitter.com/nasyrov_ildar",
'category': 'Discuss',
'version': '1.0.0',
'version': '1.1.0',
'depends': ['mail'],
'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 dateutil
import pytz
import simplejson
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')
res = requests.get(message_url, headers={'Accept': 'message/rfc2822'}, auth=('api', api_key))
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('mailgun.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"]["state"] == "active":
cron_record.write({'active': False})
Loading…
Cancel
Save