diff --git a/mailgun/__openerp__.py b/mailgun/__openerp__.py index 50f9277..a8e2469 100644 --- a/mailgun/__openerp__.py +++ b/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', ], } diff --git a/mailgun/data/cron.xml b/mailgun/data/cron.xml new file mode 100644 index 0000000..7c53db1 --- /dev/null +++ b/mailgun/data/cron.xml @@ -0,0 +1,14 @@ + + + + + Mailgun - domain verification + 10 + minutes + -1 + True + ir.config_parameter + mailgun_verify + + + diff --git a/mailgun/doc/changelog.rst b/mailgun/doc/changelog.rst new file mode 100644 index 0000000..3535b7e --- /dev/null +++ b/mailgun/doc/changelog.rst @@ -0,0 +1,13 @@ +Changelog +========= + +`1.1.0` +------- + +- ADD: automatic domain verification + +------- +`1.0.0` +------- + +- Init version diff --git a/mailgun/models.py b/mailgun/models.py index 5a246b4..7fa1136 100644 --- a/mailgun/models.py +++ b/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})