跳至內容
選單
此問題已被標幟
1 回覆
5796 瀏覽次數

Hey Guys 

Is there a way to avoid sending emails in Development / staging environment to customers/suppliers (a parameter to add, a context ....etc)?

NB: There is the solution to disable the outgoing servers, but I would like to keep it to test it for testing notifications, emails for users ...etc

I hope I was clear :) & thanks a lot

頭像
捨棄
最佳答案

Hi Othmane,

For which model/module/form, you want to avoid?

You need to set context flag to that model's message_post() and this method create mail record so context pass to mail creation method and in that method you can check condition that context flag found than block email sending otherwise send email.

I am giving you hint.

1) Basically email send when you send message from chatter (bottom of any form), so in that model of that form, there is a method called message_post() thhis method send mail. So here you can add context flag.

2) So where to check context flag?:
There is a method in mail module (mail/models/res_partner(line no: 88-191)), the method _notify(), will prepare mail data and send mail.

So in that method go to line no: 149 (email = Mail.create(create_values))

and add condition here to block email sending.

You can add code like

if not self._context.get('CONTEXT_FLAG'):
# Line no: 149-164
email = Mail.create(create_values)

if email and recipient_ids:
    notifications = self.env['mail.notification'].sudo().search([
        ('mail_message_id', '=', email.mail_message_id.id),
        ('res_partner_id', 'in', list(recipient_ids))
    ])
    notifications.write({
        'is_email': True,
        'mail_id': email.id,
        'is_read': True,  # handle by email discards Inbox notification
        'email_status': 'ready',
    })

emails |= email
email_pids.update(recipient_ids)

I know it's innocent thing, but if you want to block for specific purpose then you need to custome code like this.

I hope it will helpful for you.

Thanks and regards
Haresh Kansara

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
8月 19
8685
0
4月 18
2748
0
5月 24
2024
0
2月 24
1564
2
3月 23
3870