diff --git a/mail_queue_send_limit/README.rst b/mail_queue_send_limit/README.rst new file mode 100644 index 00000000..3123e3fb --- /dev/null +++ b/mail_queue_send_limit/README.rst @@ -0,0 +1,90 @@ +======================= +Rate limit mail sending +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/8.0/mail_queue_send_limit + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-8-0/social-8-0-mail_queue_send_limit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/205/8.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to rate limit the mail queue job for situation when you have to use an SMTP server which has a rate limit on connections or mails to send. + +The error message you'll get in such a case is:: + + 4.7.0 Too many login attempts, please try again later. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +#. go to Settings/Technical/Parameters/System parameters to edit the value of ``mail_queue_send_limit.limit`` which is the amount of mails to send per queue run +#. edit your mail queue cronjob to run just as often that your SMTP server accepts the amount of mails you filled in above + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Therp BV + +Contributors +~~~~~~~~~~~~ + +* Holger Brunn + +Other credits +~~~~~~~~~~~~~ + +* Odoo Community Association: `Icon `_. + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_queue_send_limit/__init__.py b/mail_queue_send_limit/__init__.py new file mode 100644 index 00000000..cff20de5 --- /dev/null +++ b/mail_queue_send_limit/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/mail_queue_send_limit/__openerp__.py b/mail_queue_send_limit/__openerp__.py new file mode 100644 index 00000000..35f42bd4 --- /dev/null +++ b/mail_queue_send_limit/__openerp__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Rate limit mail sending", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Tools", + "summary": "Send only a fixed amount of mails per queue run", + "depends": [ + 'mail', + ], + "data": [ + "data/ir_config_parameter.xml", + ], +} diff --git a/mail_queue_send_limit/data/ir_config_parameter.xml b/mail_queue_send_limit/data/ir_config_parameter.xml new file mode 100644 index 00000000..981a4d99 --- /dev/null +++ b/mail_queue_send_limit/data/ir_config_parameter.xml @@ -0,0 +1,9 @@ + + + + + mail_queue_send_limit.limit + 100 + + + diff --git a/mail_queue_send_limit/models/__init__.py b/mail_queue_send_limit/models/__init__.py new file mode 100644 index 00000000..d8f43c2c --- /dev/null +++ b/mail_queue_send_limit/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import mail_mail diff --git a/mail_queue_send_limit/models/mail_mail.py b/mail_queue_send_limit/models/mail_mail.py new file mode 100644 index 00000000..49a0c20f --- /dev/null +++ b/mail_queue_send_limit/models/mail_mail.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openerp import api, models + + +class MailMail(models.Model): + _inherit = 'mail.mail' + + @api.model + def process_email_queue(self, ids=None): + if not ids: + ids = self.search( + [('state', '=', 'outgoing')] + self.env.context.get( + 'filters', [] + ), + limit=int(self.env['ir.config_parameter'].get_param( + 'mail_queue_send_limit.limit', '100', + )), + ).ids + return super(MailMail, self).process_email_queue(ids=ids) diff --git a/mail_queue_send_limit/readme/CONFIGURE.rst b/mail_queue_send_limit/readme/CONFIGURE.rst new file mode 100644 index 00000000..1e77a0c2 --- /dev/null +++ b/mail_queue_send_limit/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +To configure this module, you need to: + +#. go to Settings/Technical/Parameters/System parameters to edit the value of ``mail_queue_send_limit.limit`` which is the amount of mails to send per queue run +#. edit your mail queue cronjob to run just as often that your SMTP server accepts the amount of mails you filled in above diff --git a/mail_queue_send_limit/readme/CONTRIBUTORS.rst b/mail_queue_send_limit/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..b120a956 --- /dev/null +++ b/mail_queue_send_limit/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Holger Brunn diff --git a/mail_queue_send_limit/readme/CREDITS.rst b/mail_queue_send_limit/readme/CREDITS.rst new file mode 100644 index 00000000..cc056a80 --- /dev/null +++ b/mail_queue_send_limit/readme/CREDITS.rst @@ -0,0 +1 @@ +* Odoo Community Association: `Icon `_. diff --git a/mail_queue_send_limit/readme/DESCRIPTION.rst b/mail_queue_send_limit/readme/DESCRIPTION.rst new file mode 100644 index 00000000..48a4d098 --- /dev/null +++ b/mail_queue_send_limit/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module allows you to rate limit the mail queue job for situation when you have to use an SMTP server which has a rate limit on connections or mails to send. + +The error message you'll get in such a case is:: + + 4.7.0 Too many login attempts, please try again later. diff --git a/mail_queue_send_limit/static/description/icon.png b/mail_queue_send_limit/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mail_queue_send_limit/static/description/icon.png differ diff --git a/mail_queue_send_limit/static/description/index.html b/mail_queue_send_limit/static/description/index.html new file mode 100644 index 00000000..6ce4b8b5 --- /dev/null +++ b/mail_queue_send_limit/static/description/index.html @@ -0,0 +1,439 @@ + + + + + + +Rate limit mail sending + + + +
+

Rate limit mail sending

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runbot

+

This module allows you to rate limit the mail queue job for situation when you have to use an SMTP server which has a rate limit on connections or mails to send.

+

The error message you’ll get in such a case is:

+
+4.7.0 Too many login attempts, please try again later.
+
+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. go to Settings/Technical/Parameters/System parameters to edit the value of mail_queue_send_limit.limit which is the amount of mails to send per queue run
  2. +
  3. edit your mail queue cronjob to run just as often that your SMTP server accepts the amount of mails you filled in above
  4. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+
    +
  • Odoo Community Association: Icon.
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_queue_send_limit/tests/__init__.py b/mail_queue_send_limit/tests/__init__.py new file mode 100644 index 00000000..84b1d6ce --- /dev/null +++ b/mail_queue_send_limit/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import test_mail_queue_send_limit diff --git a/mail_queue_send_limit/tests/test_mail_queue_send_limit.py b/mail_queue_send_limit/tests/test_mail_queue_send_limit.py new file mode 100644 index 00000000..66286ae4 --- /dev/null +++ b/mail_queue_send_limit/tests/test_mail_queue_send_limit.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from mock import patch +from openerp.tests.common import TransactionCase + + +class TestMailQueueSendLimit(TransactionCase): + def test_mail_queue_send_limit(self): + limit = int(self.env.ref('mail_queue_send_limit.param_limit').value) + for i in range(limit + 1): + self.env['mail.mail'].create({ + 'type': 'email', + 'state': 'outgoing', + }) + with patch.object( + self.env.registry.models['mail.mail'].__class__, 'send' + ) as send: + self.env['mail.mail'].process_email_queue() + send.assert_called_once() + self.assertEqual( + len(send.call_args[0][2]), limit, + )