Speed up Odoo using Postfix
Integration of a local Postfix server for faster and more reliable message delivery
8 June, 2023 by
Speed up Odoo using Postfix
manaTec GmbH, Jan Wiegand
 


If the e-mail system of a company using Odoo software is based on either Office365 or Google Workspace, it is often advisable to use the corresponding SMTP relays of these providers directly. This approach ensures that the full e-mail functionality of Odoo can be used optimally.

In addition, the domain's DKIM header is set correctly and thus e-mails are less likely to end up in the spam folder. This is due to the higher trust that Microsoft and Google SMTP servers enjoy compared to other e-mail providers. A plus point is that no additional maintenance or configuration is required. This enables smooth integration and use for most companies.

For companies that experience heavy use of outgoing e-mail messages, such as project-oriented contexts, this configuration may be perceived as insufficient. This is not due to an actual slowness of the Odoo server, but to the way Odoo handles the sending of e-mails.

How does Odoo send e-mails?

Odoo offers two different ways to handle outgoing e-mails. The first variant is that Odoo collects the outgoing e-mails and then processes them in a run via its cron thread. This is done without any direct involvement of the end user, which means they don't notice anything. This method is well suited for general e-mail traffic. The second variant is particularly interesting for user experience, especially for communication in projects, tickets or other messages sent to a contact. In these cases, the e-mails are sent directly without being collected and processed in the background beforehand. This ensures immediate delivery of the messages.

However, in situations where, for example, there are many followers in a project and each of them receives the message in question by e-mail, there may be a noticeable delay for the Odoo user. If many of the recipients already have a large number of e-mails in their inbox, this can cause some slowdown.

So where is the problem?

The impression that the Odoo system is slow is mainly due to a design decision in the framework. When sending messages, the user interface is blocked by a progress circle and is only unblocked after the entire sending process is complete. This is because the framework is designed to send messages one at a time. To change this perception, fundamental design changes would need to be made to the framework. For example, one possible solution would be to run the dispatch in a separate thread and simply display a notification to the user whether the dispatch was successful or not. However, implementing such a change would be extremely complex and costly.

The question of whether the waiting times are worthwhile is therefore crucial. In a test with nine e-mail messages, times of between 2.5 and 3.5 seconds were measured, with outliers of over 10 seconds. These times vary depending on the e-mail provider.

Basically, Odoo uses the standard SMTP Python library to open an SMTP session with the SMTP relay and send the individual e-mail messages to the respective recipients within this session. This is already the fastest way to send e-mails directly via Python. However, since Odoo does not run this in a separate thread, wait times always occur unless it is helped along.

The performance boost with Postfix

An effective solution to speed up communication significantly is to additionally integrate a local Postfix server between Odoo and the relay server. This configuration change reduces the waiting time to about 0.03 seconds in our tests, which makes an immediately noticeable difference. However, the use of a local Postfix server represents an additional component that must be included in the configuration and also requires some maintenance.

By making this additional investment, companies dissatisfied with Odoo's speed can benefit from significant improvements. The integration of a local Postfix server between Odoo and the relay servers not only shortens waiting times, but also optimizes the e-mail sending process overall.

Configuration for testing

To configure Postfix for a custom test, the following steps can be followed: However, it is important to note that this configuration includes only the most basic functionality. Other settings, such as security, authentication or filtering, should be added according to individual requirements.

Provided that the SMTP relay configuration for the Odoo server is already preset in Microsoft Office 365 or Google Workspace, for example by using IP addresses and StartTLS for proper authentication. Our blog post on catch-all mit Office 365 describes this setup in detail. In this case, it is sufficient to install Postfix on the Odoo server and add or adjust the following lines in the /etc/postfix/main.cf file.

Example google smtp-relay

relayhost = smtp-relay.gmail.com:587
smtp_tls_security_level=may
inet_interfaces = loopback-only

The configuration for Microsoft Office 365 has some similarities. The relay host entry is composed of the MX record of the domain and port 25. Additionally, it is important to set the parameter "smtp_tls_security_level" to "may" to enable secure communication. Since the Microsoft Relay service also supports StartTLS, this encryption option is used automatically. Using the MX record as the relay host ensures that outgoing e-mails are routed to the Office 365 servers via the correct path. Port 25 is the default port for SMTP communication and allows e-mails to be sent smoothly. To integrate the local Postfix SMTP server in the Odoo configuration, the outgoing server is set to "localhost" with port 25 in the Odoo configuration interface. In this case, communication takes place without encryption and no specific user is specified. Certain settings such as "From Filter", "Alias Domain" and "Default From" should nevertheless be adjusted according to your own domain and individual requirements. These settings are essential to ensure that outgoing e-mails are processed correctly and that no potential errors or e-mail spoofing situations occur.

In the present test configuration, Postfix does not automatically adopt these specific settings for Odoo. It is therefore of great importance that the corresponding settings are carefully made in the Odoo configuration interface. This ensures that the e-mails are correctly provided with the specified sender information and that no security gaps or forgeries occur.

Contact us now to learn more about integrating a local Postfix server and achieve faster as well as reliable messaging in Odoo!

 
Open Source ERP Systems
Revolutionizing business management with the Odoo ERP system