# Define many recipients on notification email

**URL:** <https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751>\
**Category:** Developer\
**Tags:** notification\
**Created:** [May 21, 2020, 1:04pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751 "2020-05-21T13:04:52Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)\
**Post date:** [May 21, 2020, 1:04pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/1 "2020-05-21T13:04:52Z")

</div>

I need to define many email addresses on recipients (or secondary recipients) field in notification email.  
I first thought to define all emails in a single contact mechanisms with comma separator, but it does not work in some email servers for security policies; each email must be an item on the recipients list.

So I’m wondering if it should be considered on the module when extracting email from party/employee/contact mechanism.  
Of course I can add more recipients fields if it is not a desired feature/bugfix.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [May 21, 2020, 1:44pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/2 "2020-05-21T13:44:41Z")

</div>

> [@sergyo](#):
>
> I need to define many email addresses on recipients (or secondary recipients) field in notification email.  
> I first thought to define all emails in a single contact mechanisms with comma separator, but it does not work in some email servers for security policies; each email must be an item on the recipients list.

The module supports by default xxx2Many fields and when used it will send the email to each record of the field.

> [@sergyo](#):
>
> Of course I can add more recipients fields if it is not a desired feature/bugfix.

Why you need more recipients? Could you please give more details about the type of recipients that will receive the notification?

---

<div class="post-metadata">

**Author:** ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)\
**Post date:** [May 21, 2020, 2:24pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/3 "2020-05-21T14:24:25Z")

</div>

> [@pokoli](#):
>
> The module supports by default xxx2Many fields and when used it will send the email to each record of the field.

Sorry but I don’t see it. Indeed the code is ready to manage many recipients but at the end the recipients field is a Many2One.

> [@sergyo](#):
>
> Why you need more recipients? Could you please give more details about the type of recipients that will receive the notification?

Is quite simple: they need to send the message to more than one party email addresses for sales or invoices.  
Using the contact defined on document is not enough as there are cases of more than 2 addresses.  
Just comment is not a requirement of a single customer, we have several with this situation. But with the trick of comma separate emails the others could work.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [May 21, 2020, 2:53pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/4 "2020-05-21T14:53:39Z")

</div>

> [@sergyo](#):
>
> the recipients field is a Many2One.

You can create a functional One2Many field with all the involved parties and use it for email notification.

> [@sergyo](#):
>
> Is quite simple: they need to send the message to more than one party email addresses for sales or invoices.  
> Using the contact defined on document is not enough as there are cases of more than 2 addresses.

If the contact fields on the document are not enought how you know which addresses are related to the parties?

> [@sergyo](#):
>
> Just comment is not a requirement of a single customer, we have several with this situation. But with the trick of comma separate emails the others could work.

Could you please explain the problems of your customers (and not only how you think it can be solved)?  
If you explain the real use case it’s easier to find a solution that works for all.

---

<div class="post-metadata">

**Author:** ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)\
**Post date:** [May 21, 2020, 3:14pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/5 "2020-05-21T15:14:50Z")

</div>

> [@pokoli](#):
>
> If the contact fields on the document are not enought how you know which addresses are related to the parties?

The addresses are always the same for a given party.

> [@pokoli](#):
>
> If you explain the real use case it’s easier to find a solution that works for all.

I think I did it … the user needs to send the email message to a set of fixed addresses according to his customer’s demand. This addresses could be personal or generic: p.e [sales@mycustomer.com](mailto:sales@mycustomer.com), [office@mycustomer.com](mailto:office@mycustomer.com), [john.thesalesman@mycustomer.com](mailto:john.thesalesman@mycustomer.com), …

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [May 21, 2020, 3:50pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/6 "2020-05-21T15:50:09Z")

</div>

> [@sergyo](#):
>
> The addresses are always the same for a given party.

Then probably the best option is to extend \_get\_addresss method of the notifications to return all the email addresses and names where you want to send the notification.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [May 21, 2020, 6:04pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/7 "2020-05-21T18:04:20Z")

</div>

Or to create define a `usage` on contact mechanism for this use case.

---

<div class="post-metadata">

**Author:** ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)\
**Post date:** [May 21, 2020, 7:09pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/8 "2020-05-21T19:09:47Z")

</div>

> [@pokoli](#):
>
> Then probably the best option is to extend \_get\_addresss method of the notifications to return all the email addresses and names where you want to send the notification.

This is what I was implementing before start this thread.

> [@ced](#):
>
> Or to create define a `usage` on contact mechanism for this use case.

But AFAIK the notification gets only the first contact mechanism of given `usage`.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [May 21, 2020, 7:35pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/9 "2020-05-21T19:35:18Z")

</div>

Or you can use a single address with a forwarding rule.  
One special customer should not increase the complexity the system.

---

<div class="post-metadata">

**Author:** ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)\
**Post date:** [May 21, 2020, 9:36pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/10 "2020-05-21T21:36:00Z")

</div>

> [@ced](#):
>
> One special customer should not increase the complexity the system.

I’m afraid I haven’t explained myself correctly because it is happening with many customers in many deployments.  
Indeed we are moving all from [electronic\_mail](https://github.com/trytonspain/trytond-electronic_mail) to notification\_email and we find a few requirements not supported.

Anyway thanks for your comments, finally I extended \_get\_address to manage email contact mechanism with many addresses separated with comma.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [May 21, 2020, 9:51pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/11 "2020-05-21T21:51:28Z")

</div>

I still find this requirement very strange. Such companies are really not structured at all to have such requirements from their suppliers. And what a waste of attention to send the same automatic email to many person in a company.

> [@sergyo](#):
>
> Anyway thanks for your comments, finally I extended \_get\_address to manage email contact mechanism with many addresses separated with comma.

I think it is a bad idea because it pervert the design and it will probably break any other module that is using contact mechanism.  
I think it is better to add support for relation field pointing to contact mechanism. But it would ignore it if it is not an email and/or its usage is not compatible.

---

<div class="post-metadata">

**Author:** ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)\
**Post date:** [May 21, 2020, 10:17pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/12 "2020-05-21T22:17:27Z")

</div>

> [@ced](#):
>
> I still find this requirement very strange. Such companies are really not structured at all to have such requirements from their suppliers.

the requirement is from their customers.

> [@ced](#):
>
> And what a waste of attention to send the same automatic email to many person in a company.

Yes it is. Checking some examples I found a case with 9 addresses.

> [@ced](#):
>
> I think it is better to add support for relation field pointing to contact mechanism. But it would ignore it if it is not an email and/or its usage is not compatible.

Could you ellaborate please?

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [May 21, 2020, 10:20pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/13 "2020-05-21T22:20:30Z")

</div>

If we allow to use contact mechanism relation, you can have a xxx2Many pointing to them as receipt.

---

<div class="post-metadata">

**Author:** ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)\
**Post date:** [May 21, 2020, 10:26pm UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/14 "2020-05-21T22:26:25Z")

</div>

Ok, so IIUC you propose to add a relation among contact mechanisms. This sounds great.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [May 22, 2020, 10:30am UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/15 "2020-05-22T10:30:25Z")

</div>

Yes but it will require first to implement [Allow contact mechanism as email notification recipients (#9363) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue9363) in order to allow the contact mechanism fields as recipients of the notification.

---

<div class="post-metadata">

**Author:** ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)\
**Post date:** [May 22, 2020, 11:31am UTC](https://discuss.tryton.org/t/define-many-recipients-on-notification-email/2751/16 "2020-05-22T11:31:29Z")

</div>

> [@pokoli](#):
>
> Yes but it will require first to implement [Allow contact mechanism as email notification recipients (#9363) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue9363) in order to allow the contact mechanism fields as recipients of the notification.

IMHO it is not a requirement but a complementary feature as contact mechanisms is already managed through party.  
But will be great to have such 2 features.
