diff --git a/mailgun/README.rst b/mailgun/README.rst index 20db777..ffc5084 100644 --- a/mailgun/README.rst +++ b/mailgun/README.rst @@ -1,11 +1,14 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png + :target: https://www.gnu.org/licenses/lgpl + :alt: License: LGPL-3 + ========= Mailgun ========= -With this module you can receive incoming messages from mailgun. +The module allows to receive incoming messages or send them to clients who uses external mail services (e.g. gmail.com) by using 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. +That is why we need this module. It fetches messages from mailgun using their API and stores them in odoo. TODO ==== @@ -24,13 +27,27 @@ Sponsors -------- * `IT-Projects LLC `__ +Maintainers +----------- +* `IT-Projects LLC `__ + + To get a guaranteed support you are kindly requested to purchase the module at `odoo apps store `__. + + Thank you for understanding! + + `IT-Projects Team `__ + Further information =================== -HTML Description: https://apps.odoo.com/apps/modules/9.0/mailgun/ +Demo: http://runbot.it-projects.info/demo/mail-addons/11.0 + +HTML Description: https://apps.odoo.com/apps/modules/11.0/mailgun/ + +Usage instructions: ``_ -Usage instructions: ``__ +Changelog: ``_ -Changelog: ``__ +Notifications on updates: `via Atom `_, `by Email `_ -Tested on Odoo 9.0 c8cd67c5d98b410cabe0a6efb3347a8a4de731d8 +Tested on Odoo 11.0 dc61861f90d15797b19f8ebddfb0c8a66d0afa88 diff --git a/mailgun/__manifest__.py b/mailgun/__manifest__.py new file mode 100644 index 0000000..2234dcf --- /dev/null +++ b/mailgun/__manifest__.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Ildar Nasyrov +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +{ + "name": """Mailgun""", + "summary": """Setup the outgoing and incoming mail flow easily by using Mailgun""", + "category": "Discuss", + "live_test_url": "http://apps.it-projects.info/shop/product/mailgun?version=11.0", + "images": ["images/mailgun_main.png"], + "version": "11.0.1.1.0", + "application": False, + + "author": "IT-Projects LLC, Ildar Nasyrov", + "support": "apps@it-projects.info", + "website": "https://it-projects.info/team/iledarn", + "license": "LGPL-3", + "price": 389.00, + "currency": "EUR", + + "depends": [ + "mail", + ], + "external_dependencies": {"python": [], "bin": []}, + "data": [ + 'data/ir_cron_data.xml', + ], + "demo": [ + ], + "qweb": [ + ], + + "post_load": None, + "pre_init_hook": None, + "post_init_hook": None, + "uninstall_hook": None, + + "auto_install": False, + "installable": True, + + "demo_title": "Mailgun", + "demo_addons": [], + "demo_addons_hidden": [], + "demo_url": "mailgun", + "demo_summary": "Easy to send outgoing and fetch incoming messages by using Mailgun", + "demo_images": [ + "images/mailgun_main.png", + ] +} diff --git a/mailgun/__openerp__.py b/mailgun/__openerp__.py deleted file mode 100644 index f2bc525..0000000 --- a/mailgun/__openerp__.py +++ /dev/null @@ -1,14 +0,0 @@ -{ - 'name': "Mailgun", - 'author': "IT-Projects LLC, Ildar Nasyrov", - 'license': 'LGPL-3', - "support": "apps@it-projects.info", - 'website': "https://twitter.com/nasyrov_ildar", - 'category': 'Discuss', - 'version': '1.1.0', - 'depends': ['mail'], - 'data': [ - 'data/cron.xml', - ], - 'installable': False -} diff --git a/mailgun/data/cron.xml b/mailgun/data/cron.xml deleted file mode 100644 index edbeb03..0000000 --- a/mailgun/data/cron.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - Mailgun - domain verification - 10 - minutes - 288 - True - ir.config_parameter - mailgun_verify - - - diff --git a/mailgun/data/ir_cron_data.xml b/mailgun/data/ir_cron_data.xml new file mode 100644 index 0000000..bdb63f3 --- /dev/null +++ b/mailgun/data/ir_cron_data.xml @@ -0,0 +1,15 @@ + + + + + Mailgun - domain verification request + + 10 + minutes + 10 + code + model.mailgun_verify() + + + + diff --git a/mailgun/doc/changelog.rst b/mailgun/doc/changelog.rst index c422520..8f24aaa 100644 --- a/mailgun/doc/changelog.rst +++ b/mailgun/doc/changelog.rst @@ -1,6 +1,3 @@ -Updates -======= - `1.1.0` ------- diff --git a/mailgun/doc/index.rst b/mailgun/doc/index.rst index 0d3ac56..f235356 100644 --- a/mailgun/doc/index.rst +++ b/mailgun/doc/index.rst @@ -2,55 +2,92 @@ Mailgun ========= -Usage -===== +Installation +============ + +* `Install `__ this module in a usual way + +Configuration +============= + +Mailgun-side +------------ * register or log in http://mailgun.com -* On https://mailgun.com/app/domains click on you domain, e.g. sandbox123...mailgun.org domain. Here you can see all information needed to configure odoo outgoing mail feature +* Open menu ``[[ Domains ]]`` and click on your domain, e.g. ``sandbox123*****.mailgun.org`` domain. Here you can see all the information needed to configure odoo outgoing mail feature +* Please note that state of your domain should be ``Active`` before you can use it. If it is ``Unverified``, verify it first using Mailgun FAQ - `How do I verify my domain `__ +* if you are using your sandbox domain, add Authorized Recipient first (Sandbox domains are restricted to `authorized recipients `__ only) +* create new Route - * if you in sandbox domain, add Authorized Recepient - * Copy API Key value into odoo - - * Open menu ``Settings / Parameters / System Parameters`` - * Create new parameter - - * key: ``mailgun.apikey`` - * Value: API Key from mailgun (``key-...``) - * click Save - - * Copy smtp credentials into odoo + * Open menu ``[[ Routes ]]`` + * Click ``[Create Route]`` button + + * **Expression Type** - ``Custom`` + * **Raw Expression** - ``match_recipient('.*@')`` + * **Actions** - ``Store and notify``, ``http:///mailgun/notify`` - * open ``Settings / Technical / Email / Outgoing Mail Servers`` +Odoo-side +--------- - * delete localhost - * create new server +* `Activate Developer Mode `__ +* Configure **Outgoung mail server** - * Description: ``mailgun`` - * SMTP Server: ``smtp.mailgun.org`` - * Connection Security: ``SSL/TLS`` - * Username: e.g. ``postmaster@sandbox123....mailgun.org`` - * Password: ``...`` (copy ``Default Password`` from mailgun) + * Open menu ``[[ Settings ]] >> Technical >> Email >> Outgoing Mail Servers`` + * Edit ``localhost`` record or create new one with the following: - * From odoo menu ``Settings / General Settings`` edit Alias Domain - - * Put your mailgun domain here. E.g. sandbox123...mailgun.org - * Click 'Apply' button + * **Description** - ``Mailgun`` + * **SMTP Server** - take from Mailgun **SMTP Hostname** (usually, it is ``smtp.mailgun.org``) + * **Connection Security** - ``SSL/TLS`` + * **Username** - take from Mailgun **Default SMTP Login** + * **Password** - take from Mailgun **Default Password** + * Click ``[Test Connection]`` button to check the connection and then ``[Save]`` -* From https://mailgun.com/cp/routes create new route +* Configure **Incoming mail feature** - * Priority: ``0`` - * Filter expression: ``catch_all()`` - * Actions: ``store(notify="http:///mailgun/notify")`` + * Configure catchall domain -* Set admin's email alias. Open menu ``Settings / Users / Users`` + * Open menu ``Settings / General Settings``, check **External Email Servers** and edit **Alias Domain** - set it from Mailgun **Domain Name** + * Click ``[Save]`` button - * choose your user and click ``[Edit]`` - * On Preference tab put alias into Messaging Alias field and click ``[Save]``. E.g. ``admin@sandbox...mailgun.org`` + * Set Mailgun API credentials + + * Open menu ``[[ Settings ]] >> Parameters >> System Parameters`` + * Create new parameter + + * key: ``mailgun.apikey`` + * Value: API Key from mailgun (``key-...``) + * Click ``[Save]`` button + + * Configure mail aliases and emails for users + + * Open menu ``[[ Settings ]] >> Users >> Users`` + * Select the ``Administrator`` user (for example, you should configure all your users the same way but using different aliases) and click ``[Edit]`` + * On Preference tab edit **Alias** field - create new mail alias, e.g. ``admin@`` with the following settings + + * **Alias Name** - ``admin`` + * **Aliased Model** - ``Users`` + * **Record Thread ID** - ``1`` + * **Default Values** - ``{}`` + * **Alias Contact** - ``Everyone`` + * **Security Owner** - ``Administrator`` + * **Parent Model** - Not set + * **Parent Record Thread ID** - ``0`` + + * Open user's **Related Partner** and edit **Email** field - usually it should be the same as mail alias name (``admin@> Email >> Emails`` to create a message +* Click ``[Send Now]`` button +* RESULT: receive the message in your mail client (e.g. on gmail.com) +Incoming +-------- +* Create new message from your mail client to e.g. ``admin@`` +* Open menu ``[[ Discuss ]]`` in Odoo +* RESULT: See your message there diff --git a/mailgun/images/mailgun_main.png b/mailgun/images/mailgun_main.png new file mode 100644 index 0000000..5916699 Binary files /dev/null and b/mailgun/images/mailgun_main.png differ diff --git a/mailgun/models.py b/mailgun/models.py deleted file mode 100644 index 43ba8df..0000000 --- a/mailgun/models.py +++ /dev/null @@ -1,35 +0,0 @@ -import requests -import simplejson - -from openerp import models, api - - -import logging -_logger = logging.getLogger(__name__) - - -class MailThread(models.AbstractModel): - _inherit = 'mail.thread' - - @api.model - def mailgun_fetch_message(self, message_url): - 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), verify=False) - self.message_process(False, res.json().get('body-mime')) - - -class IrConfigParameter(models.Model): - _inherit = ['ir.config_parameter'] - - @api.model - def mailgun_verify(self): - verified = self.get_param('mailgun.verified') - if verified: - return - api_key = self.get_param('mailgun.apikey') - mail_domain = self.get_param('mail.catchall.domain') - 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": - self.set_param('mailgun.verified', '1') diff --git a/mailgun/models/__init__.py b/mailgun/models/__init__.py new file mode 100644 index 0000000..a048595 --- /dev/null +++ b/mailgun/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import mail_thread +from . import ir_config_parameter diff --git a/mailgun/models/ir_config_parameter.py b/mailgun/models/ir_config_parameter.py new file mode 100644 index 0000000..97a5e73 --- /dev/null +++ b/mailgun/models/ir_config_parameter.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +import requests +import simplejson + +from openerp import models, api + +import logging +_logger = logging.getLogger(__name__) + + +class IrConfigParameter(models.Model): + _inherit = ['ir.config_parameter'] + + @api.model + def mailgun_verify(self): + verified = self.sudo().get_param('mailgun.verified') + if verified: + return + api_key = self.sudo().get_param('mailgun.apikey') + mail_domain = self.sudo().get_param('mail.catchall.domain') + 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": + self.sudo().set_param('mailgun.verified', '1') diff --git a/mailgun/models/mail_thread.py b/mailgun/models/mail_thread.py new file mode 100644 index 0000000..04d33fa --- /dev/null +++ b/mailgun/models/mail_thread.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +import requests + +from odoo import models, api + + +import logging +_logger = logging.getLogger(__name__) + + +class MailThread(models.AbstractModel): + _inherit = 'mail.thread' + + @api.model + def mailgun_fetch_message(self, message_url): + 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), verify=False) + self.message_process(False, res.json().get('body-mime')) diff --git a/mailgun/static/description/icon.png b/mailgun/static/description/icon.png new file mode 100644 index 0000000..79f7d8f Binary files /dev/null and b/mailgun/static/description/icon.png differ diff --git a/mailgun/static/description/index.html b/mailgun/static/description/index.html new file mode 100644 index 0000000..972a1f8 --- /dev/null +++ b/mailgun/static/description/index.html @@ -0,0 +1,332 @@ +
+
+
+

Mailgun

+

Easy to setup the outgoing and incoming mail flow

+
+
+
+ +
+
+
+

+

+ The module provides Odoo and Mailgun integration to be able to easily configure Outgoing and Incoming mail flow. +
+ From Mailgun side you get: +
    +
  • + Powerful Sending Infrastructure +
  • +
  • + Intelligent Inbound Routing & Storage +
  • +
  • + Tracking and Analytics +
  • +
  • + Email Validation +
  • +
+
+
+

+
+
+
+ +
+
+

Mailgun Configuration

+

Manage Domains

+
+

+ +

    +
  • + Create account on Mailgun service +
  • +
  • + Add domain in Domains menu +
  • +
+ Note that the state of your domain should be Active to be able to use it from Odoo side. To verify it follow the instruction How do I verify my domain + +

+
+
+ +
+
+
+ +
+
+
+

+ + Click on added domain name and see all the information needed to configure your Incoming and Outgoing mail feature. + +

+
+
+ +
+
+
+ +
+
+
+

+ + If you use sandbox domain, add Authorized Recipient first (sandbox domains are restricted to authorized recipients) + +

+
+
+ +
+
+
+ +
+
+
+ +
+
+

Routes

+
+

+ + Navigate to Routes menu and create a new route + +

+
+
+ +
+
+
+ +
+
+
+

+ + Set the following fields and values: +

    +
  • + Expression Type: Custom +
  • +
  • + Raw Expression: match_recipient('.*@your_mail_domain') +
  • +
  • + Actions: +
      +
    • + Check the box Store and notify +
    • +
    • + Put there http://your_odoo_domain/mailgun/notify +
    • + +
    +
    +

    +
+
+ +
+
+

+ + Now everything is ready to move to Odoo configuration. + +

+
+
+
+ +
+
+

Odoo Configuration

+

Outgoing Mail Feature

+
+

+ + At first, activate the developer mode. Then go to Settings → Technical → Email → Outgoing Mail Servers menu and populate the following fields: +

    +
  • + Description - e.g. Mailgun +
  • +
  • + SMTP Server - smtp.mailgun.org +
  • +
  • + Connection Security - SSL/TLS +
  • +
  • + Username - use Default SMTP Login from mailgun +
  • +
  • + Password - use Default Password from mailgun +
  • +
+ Once the fields are populated, click Test Connection button to check the connection to smtp server. If everything is ok, you can see popup message Connection Test Succeeded! Everything seems properly set up! and you are able to send messages now. + +

+
+
+ +
+
+
+ +
+
+

Incoming Mail Feature

+
+

+ + Note that to setup incoming mailing, it is not required to setup Incoming Mail Server. +
+ Open Settings → General Settings menu: +

    +
  • + Check the box External Email Servers +
  • +
  • + Set as Alias Domain the domain name from Mailgun +
  • +
+ Save the changes. + +

+
+
+ +
+
+
+ +
+
+
+

+ + Setup mailgun API credentials in Settings → Parameters → System Parameters menu. Create new parameter: +

    +
  • + Key - mailgun.apikey +
  • +
  • + Value - key-12345... +
  • +
+ +

+
+
+ +
+
+
+ +
+
+
+

+ + Now you can configure mail aliases for users. Go to Settings → Users menu and open user form (e.g. for Administrator). Then switch to Preferences tab and select an existing alias or create new one in the Alias field. + +

+
+
+ +
+
+
+ +
+
+
+

+ + Open the user's related partner and set Email - the email is used for replying on user messages + +

+
+
+ +
+
+
+ +
+
+
+

+ + + Everything is done! It's time to send/receive email messages now! + + +

+
+
+
+ +
+
+
+

Need our service?

+

Contact us by email or fill out request form

+ +
+
+
+
+ Tested on Odoo
11.0 community +
+
+ Tested on Odoo
11.0 enterprise +
+
+
+
+
diff --git a/mailgun/static/description/mailgun_add_domain.png b/mailgun/static/description/mailgun_add_domain.png new file mode 100644 index 0000000..9482ca5 Binary files /dev/null and b/mailgun/static/description/mailgun_add_domain.png differ diff --git a/mailgun/static/description/mailgun_auth_recipients.png b/mailgun/static/description/mailgun_auth_recipients.png new file mode 100644 index 0000000..fc6c256 Binary files /dev/null and b/mailgun/static/description/mailgun_auth_recipients.png differ diff --git a/mailgun/static/description/mailgun_auth_recipients_form.png b/mailgun/static/description/mailgun_auth_recipients_form.png new file mode 100644 index 0000000..3587c41 Binary files /dev/null and b/mailgun/static/description/mailgun_auth_recipients_form.png differ diff --git a/mailgun/static/description/mailgun_domain_details.png b/mailgun/static/description/mailgun_domain_details.png new file mode 100644 index 0000000..9d67644 Binary files /dev/null and b/mailgun/static/description/mailgun_domain_details.png differ diff --git a/mailgun/static/description/mailgun_odoo_general.png b/mailgun/static/description/mailgun_odoo_general.png new file mode 100644 index 0000000..a9c325b Binary files /dev/null and b/mailgun/static/description/mailgun_odoo_general.png differ diff --git a/mailgun/static/description/mailgun_odoo_mail_alias.png b/mailgun/static/description/mailgun_odoo_mail_alias.png new file mode 100644 index 0000000..39f28d6 Binary files /dev/null and b/mailgun/static/description/mailgun_odoo_mail_alias.png differ diff --git a/mailgun/static/description/mailgun_odoo_outgoing.png b/mailgun/static/description/mailgun_odoo_outgoing.png new file mode 100644 index 0000000..5edb0a1 Binary files /dev/null and b/mailgun/static/description/mailgun_odoo_outgoing.png differ diff --git a/mailgun/static/description/mailgun_odoo_partner_email.png b/mailgun/static/description/mailgun_odoo_partner_email.png new file mode 100644 index 0000000..9b22e70 Binary files /dev/null and b/mailgun/static/description/mailgun_odoo_partner_email.png differ diff --git a/mailgun/static/description/mailgun_odoo_sys_param.png b/mailgun/static/description/mailgun_odoo_sys_param.png new file mode 100644 index 0000000..597574d Binary files /dev/null and b/mailgun/static/description/mailgun_odoo_sys_param.png differ diff --git a/mailgun/static/description/mailgun_route.png b/mailgun/static/description/mailgun_route.png new file mode 100644 index 0000000..028b889 Binary files /dev/null and b/mailgun/static/description/mailgun_route.png differ diff --git a/mailgun/static/description/mailgun_route_form.png b/mailgun/static/description/mailgun_route_form.png new file mode 100644 index 0000000..6cdd7b5 Binary files /dev/null and b/mailgun/static/description/mailgun_route_form.png differ