Python Odoo 10:从Odoo发送电子邮件
我继承了联系人模块并编写了sendEmail功能:Python Odoo 10:从Odoo发送电子邮件,python,email,odoo,Python,Email,Odoo,我继承了联系人模块并编写了sendEmail功能: def sendEmail(self,values): _logger.error("sendEmail Called") mail_pool = self.env['mail.mail'] values={} values.update({'subject': 'Catastrophe in Odoo'}) values
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'],
在所有这些之后,我的帐户中没有收到电子邮件。我的传出服务器也被正确配置,因为我能够向用户发送重置密码电子邮件。那么,我是否在代码中遗漏了什么呢?我认为您的问题在于,您没有正确地使用创建的记录调用
send
方法。像这样试试,它应该会起作用
result= msg_id.send()
其思想是在记录集
msg_id
上调用send方法,如新api用法中所述 这是基于您的第一个示例的我的示例,它适用于我:
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()
您是否添加了消息类型、合作伙伴ID?