Odoo-如何使用现有的odoo电子邮件模板以编程方式发送电子邮件?

时间:2019-11-28 06:28:16

标签: odoo-12

我想使用现有的odoo电子邮件模板以编程方式发送电子邮件。

3 个答案:

答案 0 :(得分:3)

使用记录ID调用send_mail对象的template方法以呈现模板。

template_id.send_mail(record_id, force_send=True)

force_send用于指定立即发送电子邮件;否则,请使用邮件队列(推荐)。

答案 1 :(得分:0)

template_obj = self.env['mail.mail'].search([search your template)]   
template_data['email_from'] = 'xyz@abc.com'
template_data['reply_to'] = 'xyz@abc.com'
template_data['subject'] = 'this is subject'
template_data['body_html'] = 'body'
template_id = template_obj.create(template_data)
template_id.send()

答案 2 :(得分:0)

Odoo 12的示例代码:

template = self.env.ref('<module>.<template_id>')
template.send_mail(self.id, force_send=True)

其中self.id是模板的model_id字段中引用的模型的记录ID,这意味着在渲染模板时将使用其数据。