0

我继承了联系人模块并编写了一个 sendEmail 函数:

def sendEmail(self,values):
            _logger.error("sendEmail Called")
            mail_pool = self.env['mail.mail']
            values={}

            values.update({'subject': 'Catastrophe in Odoo'})

            values.update({'email_to': 'anub@petra.com'})

            values.update({'body_html': 'something is wrong' })

            values.update({'body': 'someone is messing up' })     

            msg_id = mail_pool.create(values)
            _logger.error(str(msg_id))

            if msg_id:

                 result= mail_pool.send([msg_id]) 
                 _logger.error(str(result)) 

产生此日志:

2018-10-01 15:17:20,144 21332 ERROR test odoo.addons.contacts.models.models: sendEmail Called
2018-10-01 15:17:20,165 21332 ERROR test odoo.addons.contacts.models.models: mail.mail(13,)
2018-10-01 15:17:20,165 21332 ERROR test odoo.addons.contacts.models.models: True

我还在清单文件中添加了邮件:

 'depends': ['mail','base', 'contacts', 'web_readonly_bypass'],

毕竟,我的帐户中没有收到电子邮件。我的传出服务器也已正确配置,因为我能够向用户发送重置密码电子邮件。那么我在代码中遗漏了什么吗?

4

2 回答 2

1

我认为您的问题是您没有正确调用send创建记录的方法。试试这样,它应该工作

result= msg_id.send()

msg_id这个想法是在新的 api 用法中调用记录集上的方法发送作为状态。

于 2018-10-01T16:30:24.007 回答
0

This is my example based on your first exameple and it's working for me:

def send_assessment(self):
  mail_pool = self.env['mail.mail']
  values={}
  values.update({'subject': 'Catastrophe in Odoo'})
  values.update({'email_to': 'user@domain.com'})
  values.update({'body_html': 'something is wrong' })
  values.update({'body': 'someone is messing up' })
  msg_id = mail_pool.create(values)
  result =  msg_id.send()
于 2020-08-06T19:34:51.193 回答