Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] mail_single_send_several_recipients module #128

Open
wants to merge 3 commits into
base: 10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mail_single_send_several_recipients/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Mail Single Send with Several Recipients
========================================

With this module, when there are several recipients,
Odoo sends only one single e-mail with all the addressees instead of one email per address.

Credits
=======

Contributors
------------

* Chafique Delli ([email protected])
3 changes: 3 additions & 0 deletions mail_single_send_several_recipients/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
12 changes: 12 additions & 0 deletions mail_single_send_several_recipients/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
{
'name': 'Mail Single Send with Several Recipients',
'version': '10.0.1.0.0',
'category': 'Mail',
'license': 'AGPL-3',
'summary': "When there are several recipients, always send only one e-mail for all the addressees",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['mail'],
'installable': True,
}
3 changes: 3 additions & 0 deletions mail_single_send_several_recipients/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import mail_mail
29 changes: 29 additions & 0 deletions mail_single_send_several_recipients/models/mail_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

from odoo import models, api
from email.utils import formataddr


class MailMail(models.Model):
_inherit = 'mail.mail'

@api.multi
def send(self, auto_commit=False, raise_exception=False):
for mail in self:
email_to = []
for partner in mail.recipient_ids:
for partner_email in [formataddr((partner.name, partner.email))]:
email_to.append(partner_email)
mail.email_to = email_to
return super(MailMail, self).send(auto_commit=auto_commit,
raise_exception=raise_exception)

@api.multi
def send_get_mail_to(self, partner=None):
super(MailMail, self).send_get_mail_to(partner=partner)
self.ensure_one()
email_to = []
for partner in self.recipient_ids:
email_to.append(formataddr((partner.name, partner.email)))
self.recipient_ids = [(6, 0, [])]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no super ?

Why not the following :

partner=None
self.recipient_ids = [(6,0, [])]
super().send_get_mail_to()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hparfr ,
Because the super() method without partner uses the 'tools.email_split_and_format' method which uses the 'email.utils.getaddresses' method which does not list email addresses correctly.

return email_to