From e3c94a59698a0afb29654bb6948670068f7ba80b Mon Sep 17 00:00:00 2001 From: Ildar Nasyrov Date: Mon, 23 May 2016 21:35:13 +0500 Subject: [PATCH 1/4] [ADD] mailgun: automatic domain verification --- mailgun/__openerp__.py | 3 ++- mailgun/data/cron.xml | 14 ++++++++++++++ mailgun/doc/changelog.rst | 13 +++++++++++++ mailgun/models.py | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 mailgun/data/cron.xml create mode 100644 mailgun/doc/changelog.rst 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..6fec1ff 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('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}) From a04d2d9c387959dc19cc8b906c6a4b6c1aeb1199 Mon Sep 17 00:00:00 2001 From: Ildar Nasyrov Date: Mon, 23 May 2016 21:47:25 +0500 Subject: [PATCH 2/4] [FIX] mailgun: look for xml_id in this module --- mailgun/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailgun/models.py b/mailgun/models.py index 6fec1ff..c2de402 100644 --- a/mailgun/models.py +++ b/mailgun/models.py @@ -29,7 +29,7 @@ class IrConfigParameter(models.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') + cron_record = self.env.ref('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)) From 7de9562fd1999a7fe9839bfd3ed98ec800e251e0 Mon Sep 17 00:00:00 2001 From: Ildar Nasyrov Date: Mon, 23 May 2016 21:50:57 +0500 Subject: [PATCH 3/4] [FIX] look for xml_id in this module2 --- mailgun/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailgun/models.py b/mailgun/models.py index c2de402..2eb8bac 100644 --- a/mailgun/models.py +++ b/mailgun/models.py @@ -29,7 +29,7 @@ class IrConfigParameter(models.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_domain_verification') + 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)) From 4e9c5c835c28522586f9e1817a88c385d283ff76 Mon Sep 17 00:00:00 2001 From: Ildar Nasyrov Date: Mon, 23 May 2016 21:53:34 +0500 Subject: [PATCH 4/4] [FIX] mailgun: typo --- mailgun/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailgun/models.py b/mailgun/models.py index 2eb8bac..7fa1136 100644 --- a/mailgun/models.py +++ b/mailgun/models.py @@ -33,5 +33,5 @@ class IrConfigParameter(models.Model): 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": + if res.status_code == 200 and simplejson.loads(res.text)["domain"]["state"] == "active": cron_record.write({'active': False})