Browse Source
Merge pull request #197 from eLBati/add_wrong_email_notice
Merge pull request #197 from eLBati/add_wrong_email_notice
[ADD] module fetchmail_notify_error_to_senderpull/225/merge
Alexandre Fayolle
10 years ago
8 changed files with 260 additions and 0 deletions
-
50fetchmail_notify_error_to_sender/README.rst
-
22fetchmail_notify_error_to_sender/__init__.py
-
40fetchmail_notify_error_to_sender/__openerp__.py
-
27fetchmail_notify_error_to_sender/email_template_data.xml
-
30fetchmail_notify_error_to_sender/fetchmail.py
-
16fetchmail_notify_error_to_sender/fetchmail_view.xml
-
75fetchmail_notify_error_to_sender/mail_thread.py
-
BINfetchmail_notify_error_to_sender/static/description/icon.png
@ -0,0 +1,50 @@ |
|||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
|||
:alt: License: AGPL-3 |
|||
|
|||
Send notice on fetchmail errors |
|||
=============================== |
|||
|
|||
If fetchmail is not able to correctly route an email, the email is "silently" lost (you get an error message in server log). |
|||
For example, if you configure odoo mail system to route received emails according to recipient address, it may happen users send emails to wrong email address. |
|||
|
|||
This module allows to automatically send a notification email to sender, when odoo can't correctly process the received email. |
|||
|
|||
|
|||
Configuration |
|||
============= |
|||
|
|||
Configure your fetchmail server setting 'Error notice template' = 'Fetchmail - error notice'. |
|||
You can edit the 'Fetchmail - error notice' email template according to your needs. |
|||
|
|||
|
|||
Bug Tracker |
|||
=========== |
|||
|
|||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. |
|||
In case of trouble, please check there if your issue has already been reported. |
|||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback |
|||
`here <https://github.com/OCA/server-tools/issues/new?body=module:%20fetchmail_notify_error_to_sender%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
|||
|
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
.. image:: https://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: https://odoo-community.org |
|||
|
|||
This module is maintained by the OCA. |
|||
|
|||
OCA, or the Odoo Community Association, is a nonprofit organization whose |
|||
mission is to support the collaborative development of Odoo features and |
|||
promote its widespread use. |
|||
|
|||
To contribute to this module, please visit http://odoo-community.org. |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2015 Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as published |
|||
# by the Free Software Foundation, either version 3 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
from . import mail_thread |
|||
from . import fetchmail |
@ -0,0 +1,40 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2015 Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as published |
|||
# by the Free Software Foundation, either version 3 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
{ |
|||
'name': 'Send notice on fetchmail errors', |
|||
'summary': 'If fetching mails gives error, send an email to sender', |
|||
'version': '1.0', |
|||
'category': 'Tools', |
|||
'author': "Agile Business Group,Odoo Community Association (OCA)", |
|||
'website': 'http://www.agilebg.com', |
|||
'license': 'AGPL-3', |
|||
'depends': [ |
|||
'fetchmail', |
|||
], |
|||
'data': [ |
|||
'fetchmail_view.xml', |
|||
'email_template_data.xml', |
|||
], |
|||
'qweb': [ |
|||
], |
|||
'installable': True, |
|||
'auto_install': False, |
|||
} |
@ -0,0 +1,27 @@ |
|||
<?xml version="1.0" ?> |
|||
<openerp> |
|||
|
|||
<data noupdate="1"> |
|||
<!--Email template --> |
|||
<record id="email_template_error_notice" model="email.template"> |
|||
<field name="name">Fetchmail - error notice</field> |
|||
<field name="email_from">${ctx.get('sender_message').get('to')|safe}</field> |
|||
<field name="email_to">${ctx.get('sender_message').get('from')|safe}</field> |
|||
<field name="subject">Receiving error with: ${ctx.get('sender_message').get('subject')|safe}</field> |
|||
<field name="model_id" ref="fetchmail.model_fetchmail_server"/> |
|||
<field name="auto_delete" eval="True"/> |
|||
<field name="user_signature" eval="True"/> |
|||
<field name="lang">${ctx.get('lang')}</field> |
|||
<field name="body_html"><![CDATA[ |
|||
<div> |
|||
<p>Hello ${ctx.get('sender_message').get('from')},</p> |
|||
<p>we got a problem with your email: <i>${ctx.get('sender_message').get('subject')}</i></p> |
|||
<p>Maybe you used a wrong recipient address?</p> |
|||
<p><br/></p> |
|||
<p>Technical details:</p> |
|||
<p><i>${ctx.get('route_exception').message}</i></p> |
|||
</div> |
|||
]]></field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
@ -0,0 +1,30 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2015 Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as published |
|||
# by the Free Software Foundation, either version 3 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
from openerp import models, fields |
|||
|
|||
|
|||
class fetchmail_server(models.Model): |
|||
|
|||
_inherit = 'fetchmail.server' |
|||
error_notice_template_id = fields.Many2one( |
|||
'email.template', string="Error notice template", |
|||
help="Set here the template to use to send notice to sender when " |
|||
"errors occur while fetching email") |
@ -0,0 +1,16 @@ |
|||
<?xml version="1.0"?> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<record model="ir.ui.view" id="view_email_server_form"> |
|||
<field name="name">fetchmail.server.form</field> |
|||
<field name="model">fetchmail.server</field> |
|||
<field name="inherit_id" ref="fetchmail.view_email_server_form"></field> |
|||
<field name="arch" type="xml"> |
|||
<field name="active" position="after"> |
|||
<field name="error_notice_template_id"></field> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
@ -0,0 +1,75 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (C) 2015 Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as published |
|||
# by the Free Software Foundation, either version 3 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
from openerp.osv import osv |
|||
|
|||
|
|||
class mail_thread(osv.AbstractModel): |
|||
_inherit = 'mail.thread' |
|||
|
|||
def message_route_verify( |
|||
self, cr, uid, message, message_dict, route, update_author=True, |
|||
assert_model=True, create_fallback=True, allow_private=False, |
|||
context=None |
|||
): |
|||
res = () |
|||
if context is None: |
|||
context = {} |
|||
try: |
|||
res = super(mail_thread, self).message_route_verify( |
|||
cr, uid, message, message_dict, route, |
|||
update_author=update_author, assert_model=assert_model, |
|||
create_fallback=create_fallback, allow_private=allow_private, |
|||
context=context) |
|||
except ValueError as ve: |
|||
fetchmail_server_id = context.get('fetchmail_server_id') |
|||
if not fetchmail_server_id: |
|||
raise ve |
|||
fetchmail_server = self.pool['fetchmail.server'].browse( |
|||
cr, uid, fetchmail_server_id, context) |
|||
if not fetchmail_server.error_notice_template_id: |
|||
raise ve |
|||
context['sender_message'] = message |
|||
context['route_exception'] = ve |
|||
self.pool['email.template'].send_mail( |
|||
cr, uid, fetchmail_server.error_notice_template_id.id, |
|||
fetchmail_server.id, context=context) |
|||
context['error_notice_sent'] = True |
|||
return res |
|||
|
|||
def message_route( |
|||
self, cr, uid, message, message_dict, model=None, thread_id=None, |
|||
custom_values=None, context=None |
|||
): |
|||
if context is None: |
|||
context = {} |
|||
res = [] |
|||
try: |
|||
res = super(mail_thread, self).message_route( |
|||
cr, uid, message, message_dict, model=model, |
|||
thread_id=thread_id, custom_values=custom_values, |
|||
context=context) |
|||
except ValueError as ve: |
|||
if context.get('error_notice_sent'): |
|||
# avoid raising exception and setting mail message UNSEEN |
|||
return [] |
|||
else: |
|||
raise ve |
|||
return res |
After Width: 128 | Height: 128 | Size: 3.2 KiB |
Write
Preview
Loading…
Cancel
Save
Reference in new issue