odoo收件箱配置

没想到过了这么多年,odoo的邮箱配置还是如此的骨骼清奇。总结一下,最近用到的配置方法:

配置收件箱接收邮件

下面以国内常见的企业邮箱服务为例,比如阿里企业邮,腾讯企业邮,来介绍一下配置步骤。

首先在技术-邮件-收件箱服务器中创建一个邮箱。

这里推荐使用IMAP协议,可以在邮件服务器上保存一份已读邮件的备份。

如果用户名和密码配置正确,点击测试确认按钮,将收件服务器的状态变为确认状态。

配置外部邮箱别名

一般设置为公司的邮箱后缀:

配置别名

odoo的邮件分发策略是根据系统中的别名来实现的,如果你只是配置了邮件服务器而没有配置别名,odoo在收取邮件的时候就会告诉你:

1
ValueError: No possible route found for incoming message from <microsoft@outlook-address.com> to "'Administrator'" <my_address@gmail.com> (Message-Id <000f01d39516$e032a170$a097e450$@outlook-address.com>:). Create an appropriate mail.alias or force the destination model.

意思就是你必须配置一个别名来匹配你的收件箱服务器,配置别名的地方有很多,像团队,用户和设置中都有配置别名的地方。我们这里选择在用户界面上配置,然后将邮件消息显示到合作伙伴的chatter中:

Alias Model指的是将邮件消息绑定的对象模型,我们这里选择的是res.partner,记录ID就是我们用户对应的partner_id。

配置完别名 就可以测试接收邮件了。

接收到邮箱的动作

之所以选择合作伙伴,是因为我们想要实现一种当收到邮箱之后,自动分析邮件中的附件的操作(附件是一种csv文件,需要将其中的部分数据自动更新到已有的产品中去)。

从mail.thread的源码的注释来看:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mail_thread model is meant to be inherited by any model that needs to
act as a discussion topic on which messages can be attached. Public
methods are prefixed with ``message_`` in order to avoid name
collisions with methods of the models that will inherit from this class.

``mail.thread`` defines fields used to handle and display the
communication history. ``mail.thread`` also manages followers of
inheriting classes. All features and expected behavior are managed
by mail.thread. Widgets has been designed for the 7.0 and following
versions of Odoo.

Inheriting classes are not required to implement any method, as the
default implementation will work for any model. However it is common
to override at least the ``message_new`` and ``message_update``
methods (calling ``super``) to add model-specific behavior at
creation and update of a thread when processing incoming emails.

已经告诉了我们方法,在需要创建/更新的模型上定义message_new和message_update方法就可以实现我们想要的效果(阅读源码,好处多多呀)。因为我们的联系人已经创建了,因此,这里使用的是message_update方法:

1
2
3
4
5
6
class res_partner(models.Model):
_inherit = "res.partner"

@api.multi
def message_update(self, msg_dict, update_vals=None):
pass

msg_dict是包含邮件消息的字典
update_vals是需要更新记录的值

你的支持我的动力