Tuesday, 15 March 2022

Odoo 15: Send email to all followers with email template

Send Email to all followers

Here simple solution to send email to all followers or you custom the followers (exclude).

In your code file define the function to send email.

    @api.multi
    def action_lead_mail_send(self):
        group_id_list = []
        ir_model_data = self.env['ir.model.data']
        
        group_id_list.append(ir_model_data.get_object_reference('sales_team', 'group_sale_manager')[1])
        users_email = ",".join([user.email for user in self.env['res.groups'].browse(group_id_list).users if user.email])
        
        # read email template
        template_id = ir_model_data.get_object_reference('crm_notification', 'email_template_meeting')[1]
        template = self.env['mail.template'].browse(template_id)
        template.write({
            'email_to': users_email or '',
        })
        template.send_mail(self.id)
        return True

So, here you can customise the email receivers. You can also add the followers of the record.You can also exclude the followers and send email.

..Enjoy..

No comments:

Post a Comment