EMail模板

我们都知道写出一封好的电子邮件对于获得高响应率至关重要,但是您不想每次都重写相同的结构,对吗? 这就是电子邮件模板的用武之地。无需每次都重写整个电子邮件结构,您可以节省时间专注于内容。 多个模板还使您可以向正确的受众传递正确的消息,从而改善他们在公司的整体体验。

启用它并了解一些概念

The Developer mode must be activated). Then, go to Settings ‣ Technical ‣ Templates. A view of the existing templates is shown.

危险

It is highly recommended not to change the content in existing templates unless the user has prior knowledge about placeholders.

要添加一个新模板,请单击 创建 ,然后选择使用该模板的文档类型。 在下面的示例中,模板将发送给求职者。

New email template form in Odoo
电子邮件配置 下,诸如 发件人收件人(电子邮件)收件人(合作伙伴) 之类的字段需要占位符。 如果未设置 发件人 字段,则默认值为作者的电子邮件别名(如果已配置)或电子邮件地址。
高级设置 下,如果未设置 外发邮件服务器 ,则优先使用最高级的服务器。
自动删除 选项会在电子邮件发送后永久删除,从而节省了数据库的空间。

写作内容包括占位符表达式

A placeholder is a string of characters that temporarily takes the place of the final data. With email templates, for example, placeholders let you put dynamic content in order to personalize the email for the recipient.

A common use is to use it to indicate the name of the recipient in the newsletter so that each recipient gets a personalized newsletter.

Placeholders and more specifically fields that are available for a template will depend on the template you modify. One way to see the fields that are available is to check the Dynamic Placeholder Generator tab.

  1. 动态占位符生成器 选项卡下,找到您要使用的 字段

    View of the dynamic placeholder generator tab under a new template in Odoo
  2. 接下来,复制 占位符表达式 并将其粘贴到电子邮件的 正文内容*选项卡,使用 *代码视图

    View of the body code view under the content tab in Odoo
  3. 只需再次单击即可停用 代码视图 选项,并轻松设计信息。 单击 预览 ,在发送之前检查电子邮件的外观。

    View of the content with the standard body view in Odoo

Using functions with placeholders

Functions can be used along with your placeholders in order to format the data as you’d like within your mail templates, for example, the time format can be changed using a function such as format_time.

In order to use functions, you have to know the available fields to format. To know that, you have to check the fields (the properties) of the object that are available to be used.

Checking the fields (properties) available on the object

To check the fields available, click on the link next to Applies to. For the example we use the Portal: new user template, so we click on Portal user Config.

Template is capable of using the field of the defined Models.

By clicking on the link, you are redirected to the model, in this case the Portal user Config model that lists all the fields that you can use within your mail template.

Existing fields of a model

As a side note, you can also see the fields that are available by accessing the dynamic placeholder generator, as described previously.

See below an example with the email field that was added in the template and its result as well as some other placeholders already present by default.

Adding a field on a template and see the result

Using fields with functions

Now that you know the fields that can be used, you can use one of them with a function. For this example, we add the creation date, create_date field to the body of the template ‘Portal: new user’ along with the format_date function so that the user knows when he was invited.

Example of the format_date on a create_date field

As you can see we use the placeholder ${} with the format_date function which uses as a parameter the field create_date available on the current object, this gives the following line of code ${format_date(object.create_date)}.

警告

It’s really important to check that the preview is working, if it’s broken your template might appear totally blank when previewing it. We also recommend not changing the content in existing templates unless you have prior knowledge. We highly recommend duplicating the template and apply your changes within this one.

Find below the result of the e-mail received in the recipient’s mailbox with the modifications applied.

Rendering of the format_date function on a create_date field

Still by using the format_date function, you have the possibility to adapt the format of the date just in a specific email by specifying the formatting of the date as a second parameter. If not specified, the format used by default is the one defined in the settings of the language. More information on how to access these parameters can be found here.

In order to adapt the date format, the piece of code used in the above example ${format_date(object.create_date)} becomes ${format_date(object.create_date, date_format='dd -- MM -- YYYY')} here dd is the day, MM the month and YYYY the year.

Here is the result once the function is adapted in the template.

Adapted rendering of the format_date
Functions used by default within email templates

To format your data, many functions can be used, here are some examples.

注解

This list of functions is not exhaustive, meaning that all functions that are available aren’t listed in the below list, for more functions, we invite you to check the babel documentation, last but not least, modifications on the templates are considered as customization and isn’t covered by our support.

For the following examples, we will introduce mostly some date functions. By default, the format of the date used is the one defined in the settings of the language.

These settings can only be accessed when the developer mode is enabled. Once developer is enabled go to Settings ‣ Translations ‣ Languages and click on one of the languages to see all the settings such as the time format or date format used by the language.

  • format_date() - formats the date (without the time).

    Can be found on the template Purchase Order: Send PO:

    Code of the format_date on existing template Purchase

    The result will look like this:

    Rendering of the format_date on existing template Purchase
  • format_datetime() - formats the datetime, defining a specific timezone, in this case Central European Time (CET).

    Can be found on the template Event: Registration.

    Code of the format_datetime on existing template Event

    The result will look like this:

    Rendering of the format_datetime on existing template Event
  • format_time() - Similar to the format_datetime function except It’s used only for the time, not a date.

  • format_amount() - Formats a number, an amount to display the currency depending on the display setting that has been defined on the currency (the debug mode must be activated to see this feature) Accounting ‣ Configuration ‣ Currencies (before or after the amount depending on the convention).

    Code of the format_amount on existing template Sales Order

    Which will look like this:

    Rendering of the format_amount on existing template Sales Order

在邮件模板上定义默认答复

尽管“回复”字段在邮件模板中可用,但**此字段仅用于群发邮件**模式(这意味着在我们称之为批量电子邮件的模板上发送模板时)。您可以在几乎每个具有列表视图的应用中批量发送电子邮件。选择所需的记录,然后单击操作按钮。如果可以选择发送电子邮件,您将看到一个邮件编辑器,其中包含要定义的可能值:

选择多个报价后,写邮件人群发方式编写邮件。

默认情况下,您还可以在模板上定义它们:

模板上的回复字段

因此,在此字段中设置值是无用的,因为定义的值将被完全忽略。默认的*reply-to*值是默认的包罗万象的电子邮件地址,以确保您的客户和Odoo数据库之间的通信。有关 catchall 工作方式的更多信息,请查看 :ref:’如何管理入站邮件 <email_communication/inbound_messages>’。

每家公司的交易电子邮件和相应的 URL

使用Odoo时,多个事件会触发自动电子邮件的发送。这些电子邮件被称为事务性电子邮件,有时包含指向您的Odoo数据库的链接。

默认情况下,数据库生成的链接使用系统参数中定义的动态 web.base.url 键。有关此内容的更多信息:ref:’参数<域名/web-base-url>’。

如果未安装网站应用程序,则 web.base.url 密钥将始终是用于生成所有链接的默认参数。

重要的是要知道,此密钥只能有一个值,这意味着在多网站/公司数据库环境中,即使您的每个网站都有特定的域名,为共享文档或在事务性电子邮件中生成的链接也可能保持不变,无论与发送电子邮件/文档相关的网站/公司如何。

情况并非总是如此,因为某些Odoo应用程序在数据库中与网站应用程序建立了链接,这意味着在这种情况下,如果为网站定义了特定域,则电子邮件模板中生成的URL将使用在公司相应网站上定义的域。

小心

使用文档应用程序共享的文档将始终使用 web.base.url 密钥,因为共享的文档不与任何特定网站关联。这意味着URL将始终相同(web.base.url密钥值),无论它从哪个公司共享,这都是一个已知的限制!

另一方面,客户在您的Odoo电子商务网站之一上发出的销售订单与下订单的网站建立了链接。因此,为销售订单发送的电子邮件使用为相应网站定义的域名来生成链接。

有关如何配置域的更多信息,我们邀请您查看:d oc:’我们的域名文档</管理/维护/domain_names>”。

更新电子邮件模板中的翻译

电子邮件模板会自动翻译。更改翻译应该是不必要的。但是,如果出于特定原因,您想要更改某些翻译,则可以执行此操作。

与代码中的任何修改一样,请记住,未正确完成的修改(例如导致语法错误的修改)可能会破坏模板,因此,模板将显示为空白。

要编辑翻译,请从模板中执行以下步骤。

  1. 单击编辑按钮,然后单击语言按钮

    编辑模块的语言
  2. 将显示一个弹出窗口,其中包含数据库上安装的不同语言。从这里开始,编辑翻译将是可能的。不要忘记点击保存按钮以保留更改。

    应用程序模板主体的不同语言翻译。