使用电子邮件服务器在Odoo中发送和接收电子邮件

Odoo 在线或 Odoo.sh 用户

由于 Odoo 为数据库设置了自己的邮件服务器,出站和入站邮件已经可以直接使用。因此,对于 Odoo OnlineOdoo.sh 的客户来说,无需进行任何配置!

除非需要使用外部邮件服务器发送大批量的邮件,否则只需使用标准的在线Odoo数据库即可,因为它已经预先配置好了发送电子邮件的设置。

重要

Odoo 服务器每天发送电子邮件的数量受到限制,以防止滥用。对于具有 企业版 订阅的数据库,默认限制为每天发送 200 封电子邮件。在某些条件下,可以增加此限制。有关更多信息,请参阅 FAQ 或联系支持部门。

本文档的范围

This document is mainly dedicated to Odoo on-premise databases that do not benefit from an out-of-the-box solution to send and receive emails in Odoo, unlike Odoo Online and Odoo.sh. Incoming and outgoing servers must be configured for on-premise databases.

以下各节包含有关如何将外部电子邮件服务器与Odoo集成的信息。

警告

如果公司没有雇用人员来管理电子邮件服务器,强烈建议使用Odoo Online和Odoo.sh。在这些Odoo托管类型中,电子邮件的发送和接收可以立即工作,并由专业人员监控。然而,如果公司希望自己管理电子邮件服务器的声誉,可以使用自己的电子邮件服务器。有关更多信息,请参阅: 在Odoo中配置DNS记录以发送电子邮件

默认通知系统

Odoo中的文档(如CRM机会、销售订单、发票等)都有一个称为 chatter 的讨论线程。

当数据库用户在聊天中发布一条消息时,该消息将作为通知通过电子邮件发送给文档的关注者(除了发送者)。如果关注者回复该消息,回复将更新聊天,并且Odoo将作为通知将另一条回复转发给关注者。从用户或外部用户发送回聊天的消息将出现在聊天中,来自他们各自的电子邮件,或者作为其“联系人”记录中列出的名称。

这些通知是使用默认的发件地址发送的。有关更多信息,请参阅: 使用默认电子邮件地址

管理出站消息

As a system administrator, go to Settings ‣ General Settings ‣ Discuss in Odoo, and enable the Custom Email Servers option. Then, click Save. Next, click Outgoing Email Servers and click Create to create a new outgoing mail server record in Odoo. Reference the SMTP data of the external email server. Once all the information has been filled out, click Test Connection.

注解

确保发件域名在 DNS 上设置了 SPFDKIMDMARC ,将提高投递成功率。更多信息请参考 在Odoo中配置DNS记录以发送电子邮件

端口限制

请注意,在Odoo Online和Odoo.sh平台上,端口25由于安全原因被阻止。请尝试使用端口465、587或2525。

使用默认的”发件人”电子邮件地址

有时,电子邮件的“发件人”(出站)地址可能属于不同的域,这可能会成为一个问题。

例如,如果一个使用电子邮件地址 mary@customer.example.com 的客户回复了一条消息,Odoo 将尝试将相同的电子邮件重新分发给线程中的其他订阅者。但是,如果域 customer.example.com 禁止这种用法以保证安全性,Odoo 尝试重新分发的电子邮件将被一些收件人的电子邮件服务器拒绝。

为避免这个问题,Odoo会使用来自同一授权域的“发件人”地址发送所有电子邮件。

通过激活 开发者模式 并转到 设置 ‣ 技术 ‣ 参数 ‣ 系统参数 菜单,访问 系统参数

要强制指定发送电子邮件的电子邮件地址,需要在数据库的系统参数中设置以下键的组合:

  • mail.default.from: accepts the local part or a complete email address as value

  • mail.default.from_filter: accepts a domain name or a full email address as value

注解

只有对于 odoo-bin 配置或默认的 Odoo 邮件服务器, mail.default.from_filter 才有效,否则可以使用 ir.mail_server 上的 from_filter 字段设置此参数。

该字段可以是一个域名或整个电子邮件地址,也可以为空。如果发件人的电子邮件地址与此设置的过滤器不匹配,则电子邮件将使用两个系统参数的组合进行封装: mail.default.frommail.catchall.domain

Example

在下面的示例中,发件人电子邮件地址被替换为两个系统参数(mail.default.frommail.catchall.domain)的组合。这是Odoo中的默认通知配置:“Admin” <admin@example.com> => “Admin” <notifications@mycompany.com>

换句话说,如果作者的电子邮件地址与 mail.default.from_filter 不匹配,则该电子邮件地址将被 mail.default.from`(如果它包含完整的电子邮件地址)或 `mail.default.frommail.catchall.domain 的组合替换。

如果 from_filter 包含一个完整的电子邮件地址,并且 mail.default.from 与此地址相同,那么所有与 mail.default.from 不同的电子邮件地址将被封装在 mail.default.from 中。

在发件邮件服务器上使用“发件人”过滤器

The FROM Filtering field allows for the use of a specific outgoing email server depending on the From email address or domain that Odoo is sending on behalf of. This setting can be used to improve the deliverability or sending success rate of emails sent from the database. Setting the FROM Filtering field can also be used to send from different domains in a multi-company environment. Access this field in Odoo by navigating to Settings ‣ Discuss ‣ Custom Mail Servers ‣ Outgoing Mail Servers ‣ New.

传出电子邮件服务器设置和发件人筛选器设置。

当从Odoo发送电子邮件时,如果设置了 FROM Filtering 字段,则按照以下顺序选择电子邮件服务器:

  1. 首先,Odoo会搜索具有与出站邮件中定义的 From 值(电子邮件地址)相同的 FROM Filtering 值的电子邮件服务器。例如,如果 From 值(电子邮件地址)是 test@example.com ,那么只有具有 FROM Filtering 值等于 test@example.com 的电子邮件服务器会被返回。

  2. 然而,如果找不到使用 From 值的电子邮件服务器,那么 Odoo 将搜索具有与发送电子邮件中定义的 From 值(电子邮件地址)相同的 域名 的电子邮件服务器。例如,如果 From 电子邮件地址是 test@example.com ,则只返回具有 FROM Filtering 值等于 example.com 的电子邮件服务器。

如果在检查域名后找不到任何电子邮件服务器,则Odoo将返回所有没有设置任何 FROM Filtering 值的电子邮件服务器。

如果此查询没有返回结果,则Odoo将使用系统参数 mail.default.from 搜索电子邮件服务器。首先,尝试将列出的电子邮件地址与电子邮件服务器匹配,然后尝试将域名与电子邮件服务器匹配。如果没有找到电子邮件服务器,则Odoo将返回第一个外发电子邮件服务器(按优先级排序)。

注解

如果找到多个电子邮件服务器,则Odoo将根据其优先级使用第一个。例如,如果有两个电子邮件服务器,一个优先级为 10 ,另一个优先级为 20 ,那么将首先使用优先级为 10 的电子邮件服务器。

为交易和群发邮件设置不同的专用服务器

In Odoo a separate email server can be used for transactional emails and mass mailings. Example: Use Postmark or SendinBlue for transactional emails, and Amazon SES, Mailgun, Sendgrid or Mailjet for mass mailings.

重要

已经配置了默认的发件人邮件服务器。除非出于技术原因需要特定的外部发件人邮件服务器,否则不要创建替代邮件服务器。

要做到这一点,首先激活 开发者模式,然后转到 设置 ‣ 技术 ‣ 外发 邮件服务器。在那里,创建两个外发邮件服务器设置;一个用于事务性邮件,一个用于群发邮件服务器。确保通过为事务性邮件服务器提供较低的优先级数字,将优先权给予事务性服务器而不是群发邮件服务器。

现在,转到 电子邮件营销 ‣ 设置 并启用 专用服务器。选择适当的电子邮件服务器。使用这些设置,Odoo 将使用优先级较低的服务器发送 交易邮件,并使用此处选择的服务器发送群发邮件。请注意,在这种情况下,域的发件人策略框架(SPF)记录必须设置为包括 交易邮件和群发邮件服务器。

管理入站邮件

Odoo依赖于通用的电子邮件别名来获取传入的邮件。

  • Reply messages of messages sent from Odoo are routed to their original discussion thread (and to the inbox of all its followers) by the alias of the model if there is any or by the catchall alias (catchall@). Replies to messages of models that do not have a custom alias will use the catchall alias (catchall@mycompany.odoo.com). The catchall address, however, does not have another action attached to it like other aliases might, it is only used to collect replies.

  • Bounced messages are used as a Return-Path. One example this is especially useful for is in Odoo Email Marketing. In this case bounces are opt-out based on if the email bounced too many times (5) in the last month and the bounces are separated by one week. This is done to avoid blacklisting someone because of a mail server error. If these circumstances are met then the email is considered invalid and is blacklisted. A log note is added on the contact under Blacklisted Email Addresses on the Email Marketing Configuration Menu.

    在聊天中反弹的消息(在电子邮件营销之外)将填充一个红色信封,指示传递失败。这对于知道销售订单或发票未到达最终目的地很有帮助。

  • 原始消息:几个业务对象都有自己的别名,用于从传入的电子邮件中在Odoo中创建新记录:

    • 销售渠道(在 Odoo CRM 中创建 LeadsOpportunities

    • 支持渠道(在 Odoo Helpdesk 中创建 Tickets

    • 项目(在 Odoo 项目 中创建新的 任务

    • 职位(在 Odoo 招聘 中创建 应聘者

根据邮件服务器的不同,可能有多种方法来获取电子邮件。最简单和最推荐的方法是在邮件服务器中为每个Odoo别名管理一个电子邮件地址。

  • 在邮件服务器中创建相应的电子邮件地址(catchall@bounce@**sales@**等)。

  • 设置 ‣ 通用设置 ‣ 讨论 中设置 别名域名。更改 别名域名 将更改数据库的全域名。

  • 如果数据库的托管类型是Odoo本地部署,请为每个别名在Odoo中创建一个“:guilabel:Incoming Mail Server”。要创建一个新的传入服务器,请转到::menuselection:Settings --> Discuss --> Custom Mail Servers --> Incoming Mail Servers --> New`根据电子邮件提供商的设置填写表单。将:guilabel:`Actions to Perform on Incoming Mails`字段留空。一旦填写了所有信息,点击:guilabel:`TEST & CONFIRM

    Odoo中的传入邮件服务器配置。
  • 如果数据库的托管类型是Odoo Online或Odoo.sh,则建议将传入的消息重定向或转发到Odoo的域名,而不是外部电子邮件服务器。这样,可以及时接收到传入的消息。在电子邮件服务器中,应将所有电子邮件地址的重定向设置为Odoo的域名(例如 catchall@mydomain.extcatchall@mycompany.odoo.com )。

在Odoo中,所有的别名都是可自定义的。对象别名可以从其相应的配置视图中进行编辑,方法是导航到 设置 ‣ 技术菜单 ‣ 电子邮件 ‣ 别名

To edit catchall and bounce aliases, first activate the developer mode. Then, go to Settings ‣ Technical ‣ Parameters ‣ System Parameters to customize the aliases (mail.catchall.alias & mail.bounce.alias). These types of changes should be completed prior to the database going live. If a customer replies after a change is made then the system will not recognize the old alias, and the reply will not be received.

默认情况下,对于本地数据库,入站消息每5分钟获取一次。

注解

此值可以在 开发者模式 中更改。转到 设置 ‣ 技术 ‣ 自动化 ‣ 定时操作 并查找 邮件:Fetchmail 服务

防止反馈循环的系统参数

有两个系统参数可以帮助防止Odoo中发生电子邮件循环。这些参数在Odoo 16中引入,以防止别名创建过多记录,并防止在catchall回复电子邮件地址上出现反馈循环。它们存在于数据库中,但不在 系统参数 中。要覆盖以下默认值,需要将它们添加进去。

两个系统参数如下:

  • mail.gateway.loop.minutes (120 minutes by default)

  • mail.gateway.loop.threshold (20 by default)

通过首先启用 开发者模式,然后导航到 设置 ‣ 技术菜单 ‣ 参数 ‣ 系统参数,在Odoo中添加这些字段。根据需要更改这些参数的值。

When an email is received in the Odoo database on the catchall email address or on any alias, Odoo looks at the mail received for the given period of time defined in the system parameter mail.gateway.loop.minutes. If the received email was sent to an alias then Odoo will reference the mail.gateway.loop.threshold system parameter and determine the value as the number of records this alias is allowed to create in the given period of time (value of mail.gateway.loop.minutes).

In addition, when email is received to the catchall email address, Odoo will reference the emails received to the database during the set period of time (as stated by the value in the system parameter: mail.gateway.loop.minutes). Odoo will then determine whether any of the emails received match that of the email(s) being received during the specified time-frame, and will prevent a feedback loop from occurring if a duplicate email is detected.

Allow alias domain system parameter

Incoming aliases are set in the Odoo database to create records by receiving incoming emails. To view aliases set in the Odoo database, first activate the developer mode. Then, go to Settings app ‣ Technical ‣ Email section ‣ Aliases.

The following system parameter, mail.catchall.domain.allowed, set with allowed alias domain values, separated by commas, filters out correctly addressed emails to aliases. Setting the domain(s) for which the alias can create a ticket, lead, opportunity, etc., eliminates false positives where email addresses with only the prefix alias (not the domain) are present.

In some instances, matches have been made in the Odoo database when an email is received with the same alias prefix and a different domain on the incoming email address. This is true in the sender, recipient, and CC email addresses of an incoming email.

Example

When Odoo receives emails that have the name commercial prefix alias in the sender, recipient, or CC email address(es) (e.g. commercial@gmail.com, commercial@odoo.net), the database falsely treats the email as the full commercial alias (with a different domain), and therefore, creates a ticket/lead/opportunity/etc.

To add the mail.catchall.domain.allowed system parameter, first, activate the developer mode. Then, go to Settings app ‣ Technical ‣ Parameters section ‣ System Parameters. Click Create. Then, type in mail.catchall.domain.allowed for the Key field.

Next, for the Value field, add the domain(s) separated by comma(s) (if plural domains). Manually Save, and the system parameter takes immediate effect.

mail.catchall.domain.allowed system parameter set with key and value highlighted.