Table of contents
- Problem
- Available solutions
- Own email server for Odoo email communication
- Testing Odoo email communication
- Conclusion
Problem
Odooβs email communication includes sending notifications, queries of approval, communication between ERP and customers, getting of customers requests and even automatic actions based on incoming emails.
Find more in the documentation – https://www.odoo.com/documentation/15.0/applications/general/email_communication.html
For sure, all cases must be properly tested on pre production stage as it may seriously affect business processes.
The problem here is: How to test all these difficult Odoo email communications without creating a lot of email accounts on popular services?
Available solutions
Public email services
You can create accounts on popular email services such as Gmail or Yahoo, but it does not look like a good idea because you need to link phone numbers, manage tons of accounts, etc. Itβs not efficient.
Professional email testing tools
The most popular are:
- MailHog – https://mailtrap.io/blog/mailhog-explained/ (free)
MailHog is an email-testing tool with a fake SMTP server underneath. It encapsulates the SMTP protocol with extensions and does not require specific backend implementations. MailHog runs a super simple SMTP server that hogs outgoing emails sent to it. You can see the hogged emails in a web interface. MailHog is a portable tool built with Golang. You can run it on any supported platform, and Golang binary files allow you to set it up very simply β just copy and launch. It can be configured for local use or at some server to make it allowed for your QA engineers. It is recommended to use one MailHog instance per your project to avoid mixing emails from different projects.
- MailTrap – https://mailtrap.io/ (paid)
MailTrap is an email sandbox service that allows capturing SMTP traffic from staging and dev environments, automate test flows and scenarios with flexible API and analyze email content for spam score and validate HTML/CSS. It is a powerful tool that can help your QA engineers close the most of all email sending service tests.
Own email server
But what should we do when we need to test workflow with incoming email messages? Mentioned tools do not allow this. In this case it can be helpful using your own email server.
Mailcow is a great choice if you need not just testing of email sending, but testing of email exchange between Odoo ERP and customers. Thanks to Docker technology you can deploy Mailcow both locally and on your instances fast and easily. Also Mailcow is free and has most of the features that have MailHog or MailTrap, but can close needs which the aforementioned services cannot close.
Own email server for Odoo email communication
Fow our projects we use Mailcow.
Mailcow is an open source email server which is configured to deploy by Docker and gives tools for administration email server and access to mailboxes by integrated or users email clients.
You can find more details about Mailcow below:
- Documentation – https://mailcow.github.io/mailcow-dockerized-docs/
- GitHub – https://github.com/mailcow/mailcow-dockerized
Mailcow allow to solve a wide range of tasks that are connected with management flows of email messages, namely:
- Administration of domains
- Administration of mailboxes
- Administration of aliases for mailboxes and domains
- Administration of recipient maps
- Administration of BCC maps
- Administration of email filters
- Provide integrated email client and allow to manage connections from users email clients
This range of possibilities close most of all needs of configuring and testing to way email communication by Odoo ERP.
Email server installation (Mailcow)
For installing Mailcow it is recommended to use the official guide (https://mailcow.github.io/mailcow-dockerized-docs/i_u_m/i_u_m_install/).
But for using Mailcow like testing email server it have to make next changes into installation guide:
- Do next steps after “Install Mailcow” section:
1.2 Create file into Mailcow repository folder by path data/hooks/postfix/droprelay.sh and add add the following content:
This script is needed to prevent sending messages outside of a server.
1.3 Give rights to be executable for data/hooks/postfix/droprelay.sh

1.4 Add extension for original docker-compose.yml by way creating docker-compose.override.yml in the root of the repository with the following content:

2. Instead original command that presented “Start Mailcow” section

Use this one:

Email server configuration (Mailcow)
Opening the administrator panel
Configuration of testing email server at Mailcow base for work with Odoo will be done from the administrator panel. Ways of opening this panel are presented in the βStart Mailcowβ section of the official installation guide. The authorization page will look like this:

If you was not change the admin settings you should use the following data to log in:
Username: admin
Password: moohoo
After login page will look like this:

Since we got to the admin panel, we can start configuring the mail server.
Domains
Direct appointment of domains for email servers is setting of addresses in internet network that will be used for finding of messages recipients. But since it is a testing email server all exchanging of messages will happen within only our server, so we do not have to register domains for this. It is enough that the email server will be accessible by ports that are used for connecting by SMTP and IMAP protocols.
In addition to the functions described above, domains at an email server are used for configuration and management of mailboxes array which have a common domain name, that allow to group mailboxes, and set up a common and specific setting of mailboxes group.
For email testing tasks with Odoo it is recommended to create two domains which will perform the following functions:
- domain for work with Odoo (relay and aggregation of email messages which are sent and received for Odoo)
- domain for test mailboxes of Odoo customers
Let’s start creating a domain for odoo, so we should go to βConfiguration -> Mail Setupβ:


Next we should fill in the domain name (name of your choice), description, needed memory quota for domain and mailboxes, max number of mailboxes per domain (2 is enough).

Then click βAdd domain and restart SOGoβ

Domain for test mailboxes of Odoo customers are created in the same way excluding max number of mailboxes per domain, there need to fill in a value which will be enough to cover your testing needs.
As a result, you should have two domain spaces displayed as shown below:

It should be noted that at any time you can change a domain setting by clicking the “Edit” button.
Test mailboxes for Odoo customers
This type of mailboxes is needed for imitation of usual customers’ mailboxes like @gmail.com and etc., which allows it to test that Odoo registers messages correctly from customers.
For creating a test mailbox for odoo we should go to βMailboxesβ and click βAdd mailboxβ:

Then we should fill in required data for creating a mailbox, such as login, password, choose a domain (in this case we should choose domain for test mailboxes of Odoo customers) and click “Add”.


In the same way you can create as many mailboxes as you need.
Configuring SMTP relay and Catchall mailbox
Odoo have a specific way of work with emails, namely for email sending is used relay servers, which allow to send emails on behalf of anyone (there is no check that the mailbox login matches the address of the sender of the email), and mailbox, which used for email receiving, aggregates all incoming messages which should to come to Odoo.
For working email workflow in Odoo by Mailcow it is enough to set up one mailbox. First of all we should create it.


Email relay allows to set existing and non-existent mailboxes as senders, which can be useful because it is not needed to create a lot of real mailboxes. For configuration email relay that are sent form Odoo it is needed to edit settings for a previously created mailbox like show below:

Next we should to switch off checking sender for this mailbox:

Then we should check that this mailbox is accessible by SMTP and IMAP protocols and click “Save changes”:

For receiving emails to non-existent recipients it is needed a mechanism for their aggregation by some conditions. One of the most popular ways to aggregate emails is by aliases. For the current case is given configuration for aggregation incoming emails which in recipient name has the definite domain. To do this we should go to βAliases -> Aliasesβ and click βAdd aliasβ:

Then we do that all messages coming to @project-odoo.test domain will be sent to [email protected] mailbox. It should be noted that it work only with non-existent recipients, for existent recipients messages will be received by them mailboxes and it can be solved by creating BCC maps.


Mailbox for outgoing emails
Most tasks which are connected with testing email workflow is sending messages and checking that they look correct, but no matter who is the recipient of the message. For this case it is helpful to have a way to aggregate all outgoing from Odoo messages like MailHog or MailTrap. In this case it will be enough to catch all emails where the sender has defined the domain.
First of all create new mailbox by example below:



Next we should configure BCC maps. BCC (blind carbon copy) – hidden recipients of the letter, whose addresses are not shown to other recipients. Example of BCC map configuration is shown below:

At the BCC map creation wizard we should choose “BCC type” as “Sender map”, for “Local destination” choose the domain which was created for work with odoo and for “BCC destination” fill in the name of previously created mailbox. Example of this is shown below:


It should be noted some features connected to catching outgoing messages. First is necessary to configure Odoo for using an external email server and fill in the domain for work with odoo (it is described at Odoo Configuration section).
Second, odoo in case sending one message to several recipients does not use the CC rule, but sends the same message to each recipient separately without changing the “Message-Id” email header. Since “Message-Id ” is a unique identifier so it is not possible to store several emails in the same mailbox. To test that email is received by several recipients you can use several customer test mailboxes.
Domain administrator
In case work with several projects, for each of them it should be created several domains. So that every project team has access only to own domains it is needed to configure access rules to domains. It is allowed for teams to configure only their own domains without helping email server administrators. Configuration of domain administrator is shown below:





Odoo Configuration
After configuration of Mailcow we should configure Odoo for using email workflow. Fisrs of all we should enable the use of “External Email Server” and fill in the domain that was created for work with Odoo. It can be done at section βSettings -> General Settings -> Discussβ like shown below:

Then we should to check that alias of mailbox for work with Odoo is the same as set in the Odoo settings like shown below:

Outgoing Mail Server Configuration
This is needed to configure connection between Odoo and Mailcow for the possibility of sending email from Odoo. Example of outgoing mail server configuration is shown below:



Incoming Mail Server Configuration
This is needed to configure connection between Odoo and Mailcow for the possibility of receiving email to Odoo. Example of outgoing mail server configuration is shown below:



Testing Odoo email communication
For checking that Mailcow and Odoo was configured right we will reproduce a simple sending and receiving emails case. For this we will use the test customer mailbox that we created before. First of all we should change email field for someone customer in Odoo like shown below:

Then go to object which will be used for sending of a email and check that customer from previous step is presented in object followers and if it is okay send message like shown below:

After that we should to check that the email was received by recipient, so for this we will use integrated email client SOGo (documentation – https://www.sogo.nu/support.html#/documentation). Way of opening it is shown below:



As shown above, the email was successfully received by the chosen recipient.
Also we should check that this email was caught by [email protected] mailbox. For this we should log in by this mailbox.

As shown above, the email was successfully received by [email protected] mailbox.
Then we should check that we can answer at received email and your answer will be registered by Odoo in the same object. For this in the received email we should to click “Reply to”, write a message and click “Send”:


As shown above, the email was successfully received.
Also we should check [email protected] mailbox will catch an email that has a non-existent recipient so choose an Odoo customer that has the required mailbox name and send an email like we did before.



As shown above, the email was successfully received.
If we need to check message source code we can do it like shown below:


Conclusion
Using this reliable tool (Mailcow) you can make sure that all your Odoo email communications such as incoming and outgoing emails, auto actions based on incoming emails, email newsletters, etc. will work properly in production with your real mail servers (Gmail, Mailgun, Office 365, etc.).
Calculate the price for your Odoo project
How to Configure Emails to work with Office 365 and Odoo – https://ventor.tech/guides/how-to-configure-emails-to-work-with-office-365-and-odoo/
Follow our Linkedin account and subscribe to our newsletter to make sure you donβt miss updates.
1+ year of Odoo development experience
3+ years of ensuring electromagnetic compatibility for electric networks
Main skill: Python, JS, SQL, Odoo, Email Flow, S3, Redis, RabbitMQ

0 Comments