【问题标题】:Odoo - How to send an email programmatically with the existing odoo email template?Odoo - 如何使用现有的 odoo 电子邮件模板以编程方式发送电子邮件?
【发布时间】:2020-03-23 18:14:39
【问题描述】:

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

【问题讨论】:

  • 到目前为止你尝试过什么?你能在你的问题中分享你的努力/尝试代码吗?
  • 我没有尝试过,因为我不知道从哪里开始或如何在 odoo 中发送电子邮件?
  • 您可以通过网络研究这一点,因为有很多内容可以发送邮件。
  • @KevalMehta 不,因为我想使用 odoo 中现有的电子邮件模板发送电子邮件。

标签: odoo-12


【解决方案1】:

使用记录的id调用template对象的send_mail方法来渲染模板。

template_id.send_mail(record_id, force_send=True)

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

【讨论】:

  • 给定答案中的 record_id 是什么?
  • 是记录id,用来渲染模板
【解决方案2】:
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()

【讨论】:

    【解决方案3】:

    Odoo 12 的示例代码:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 2023-01-13
      • 2012-05-17
      相关资源
      最近更新 更多