Browse Source

Merge pull request #52 from iledarn/mail-addons-9.0-mailgun

[ADD] mail_mailgun: new module
pull/19/head
Ivan Yelizariev 9 years ago
parent
commit
2825436619
  1. 30
      mail_mailgun/README.rst
  2. 2
      mail_mailgun/__init__.py
  3. 12
      mail_mailgun/__openerp__.py
  4. 2
      mail_mailgun/controllers/__init__.py
  5. 57
      mail_mailgun/controllers/main.py
  6. 26
      mail_mailgun/doc/index.rst

30
mail_mailgun/README.rst

@ -0,0 +1,30 @@
==============
Mail Mailgun
==============
With this module you can receive incoming messages from mailgun.
There is no IMAP or POP3 servers on mailgun that is to be used with odoo.
That is why we need this module. It fetches messages from mailgun using their API
and stores them in odoo.
Credits
=======
Contributors
============
* Ildar Nasyrov <Nasyrov@it-projects.info>
Sponsors
========
* `IT-Projects LLC <https://it-projects.info>`_
Further information
===================
HTML Description: https://apps.odoo.com/apps/modules/VERSION/TECHNICAL_NAME/
Usage instructions: `<doc/index.rst>`_
Changelog: `<doc/changelog.rst>`_
Tested on Odoo 9.0 ODOO_COMMIT_SHA_TO_BE_UPDATED

2
mail_mailgun/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
import controllers

12
mail_mailgun/__openerp__.py

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
{
'name': "Mail Mailgun",
'author': "IT-Projects LLC, Ildar Nasyrov",
'license': 'LGPL-3',
'website': "https://twitter.com/nasyrov_ildar",
'category': 'Discuss',
'version': '1.0.0',
'depends': ['mail'],
'data': [
],
}

2
mail_mailgun/controllers/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
import main

57
mail_mailgun/controllers/main.py

@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
from openerp.addons.web import http
from openerp.addons.web.http import request
import werkzeug
import email
import requests
import simplejson
class MailMailgun(http.Controller):
def get_logs(self):
return requests.get(
"https://api.mailgun.net/v3/iledarn.ru/events",
auth=("api", "key-8345fd06eeb8b27a3b1f9a1e025519ad"),
params={"begin" : "Fri, 3 May 2013 09:00:00 -0000",
"ascending" : "yes",
"limit" : 25,
"pretty" : "yes",
"recipient" : "admin@iledarn.ru"
})
@http.route('/mail_mailgun', auth='public', csrf=False)
def incoming_mail(self, **kw):
print '\n\n\n', 'in incoming_mail ', 'kw ', kw, '\n\n\n\n'
res = self.get_logs()
logs = res.text
logs_obj = simplejson.loads(logs)
items = logs_obj.get('items')
print '\n\n\n', 'logs ', logs, '\n\n\n'
print '\n\n\n', 'logs_obj ', logs_obj, '\n\n\n'
counter = 1
for item in items:
mes = 'Item ' + str(counter)
counter = counter + 1
if 'store' in item['routes'][0]['actions'][0]:
print '\n', mes, '\n'
print item
print '\n'
@http.route('/mail_mailgun_mime', auth='public', csrf=False)
def incoming_mail_mime(self, **kw):
print '\n\n\n', 'in incoming_mail_mime ', 'kw ', kw, '\n\n\n\n'
body_mime = kw.get('body-mime')
mail_thread = request.env['mail.thread'].sudo()
# mail_thread_obj = request.env['res.partner'].sudo()
# msg_dict = mail_thread_obj.message_parse(body_mime)
# print '\n\n\n', 'msg_dict ', msg_dict, '\n\n\n'
# msg_id = msg_dict.get('message_id')
# print '\n\n\n', 'msg_id ', msg_id, '\n\n\n'
# mail_thread_obj.message_new(msg_dict)
res_id = mail_thread.message_process(model=False, message=body_mime)
print '\n\n\n', 'res_id ', res_id, '\n\n\n'

26
mail_mailgun/doc/index.rst

@ -0,0 +1,26 @@
==============
Mail mailgun
==============
Usage
=====
First we should register on mailgun.com.
After registgration there will be one domain available. E.g. sandbox5543f1479be64e5aac193406b4cdccf8.mailgun.org.
From this point we could already use API calls to mailgun API. There is API key on the
https://mailgun.com/app/domains/sandbox5543f1479be64e5aac193406b4cdccf8.mailgun.org page.
We can do all operations using mailgun API if we know our API key. More about it
on https://documentation.mailgun.com/.
There is 'Add New Domain' on the https://mailgun.com/app/domains to add new domains.
All domains that we add manually should be verified.
After adding your domain you will see the https://mailgun.com/app/domains/<yourdomain>/verify page
with instructions on how to verify and use new domain.
To receive incoming messages we specify so called routes on mailgun.
You can see more about the routes here https://documentation.mailgun.com/user_manual.html#receiving-forwarding-and-storing-messages
Instruction how to check that module works. What shall user do and what would user get, e.g.
* Open menu ...
* Click ...
Loading…
Cancel
Save