Skip to Content
Menu
This question has been flagged
3 Replies
3667 Views

Hi all,

Programatically we are sending a mail message, however when we send the message it does not show up in the record's chatter / history?

.send_mail(item.id, force_send=True, raise_exception=True)

With the above I would expect this mail message to be in the item.id's chatter. However it does not show up. I have also tried the below with no success:

.send_mail(item.id, force_send=True, raise_exception=True, email_values={'model': 'stock.picking', 'res_id': item.id})

Thanks for any help!

Avatar
Discard
Author Best Answer

I resolved this by posting the message myself through code - add this below where you are sending the mail template.

item.with_context(force_send=True).message_post_with_template(YOURTEMPLATEID, email_layout_xmlid='mail.mail_notification_light')

Avatar
Discard
Best Answer

I can not make the sample code provided to work on my end but I found a work around which might be helpful for others who like me just use Server Actions in Odoo Online. The following code will sent the email, then retreive the email sent and post it in the chatter so that it would post the completed template. 


If someone has a better way please let us know 

for applicant in records:

    email_template = env['mail.template'].browse(68)

    if email_template:

        # Send the email

        res = email_template.send_mail(applicant.id, force_send=False)

        # Extract the generated email body from mail.mail

        mail_record = env['mail.mail'].search([

            ('mail_message_id', '=', res)

        ], order="id desc", limit=1)


        if mail_record and mail_record.body_html:

            # Post the rendered email content in the chatter

            applicant.message_post(body="test" + mail_record.body_html)

Avatar
Discard
Best Answer

Hi,

In odoo there is a default function to post messages in chatter. Here is a demo for message_post().You can use this code inside your function.

def your_func(self):
body = 'Your text goes here'
self.message_post(body=body, subject='Your Subject')

Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 15
5235
0
Sep 23
996
1
Jul 16
5500
1
Sep 23
1238
0
Jun 23
2931