I am using Odoo
browser and want to generate email from template and send. I don't want to use the send_mail()
method directly. Here is my code.
data = records
template_object = env['mail.template']
template_id = template_object.search([('name', '=', 'Custom_Email_Template')]).id
for record in data:
template = template_object.browse(template_id)
email_body = template.generate_email(record.id)
email_values = {
'subject': "",
'body_html': email_body,
'email_to': '[email protected]' }
env['mail.mail'].create(email_values).send()
You need to pass the fields parameter
Example
values = template.generate_email(record.id, ['body_html'])
Edit: You can try the following in a demo database:
template = env.ref('sale.mail_template_sale_confirmation')
record = env.ref('sale.sale_order_7')
values = template.generate_email(record.id, ['body_html'])
body_html = values['body_html']