Skip to content

Commit 2f1d4d9

Browse files
committed
[IMP] Add local email testing to devel
Change from mailhog to mailpit Use roundcube as an email client to send and receive mail Dynamically load all postfix/dovecot config from environment variables, so that we only need to maintain the docker compose files
1 parent 5a5aca1 commit 2f1d4d9

8 files changed

Lines changed: 194 additions & 3 deletions

File tree

common.yaml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,47 @@ services:
3636
- db:/var/lib/postgresql/data:z
3737

3838
smtpfake:
39-
image: docker.io/mailhog/mailhog
39+
image: docker.io/axllent/mailpit
40+
environment:
41+
MP_SMTP_RELAY_ALL: "true"
42+
MP_SMTP_RELAY_ALLOW_INSECURE: "true"
43+
MP_SMTP_RELAY_PRESERVE_MESSAGE_IDS: "true"
44+
45+
mailserver_fake:
46+
image: ghcr.io/docker-mailserver/docker-mailserver:latest
47+
hostname: mailserver.manmanufacturing.com
48+
environment:
49+
PERMIT_DOCKER: connected-networks
50+
POSTFIX_INET_PROTOCOLS: ipv4
51+
ENABLE_AMAVIS: 0
52+
ENABLE_OPENDKIM: 0
53+
ENABLE_OPENDMARC: 0
54+
ENABLE_POLICYD_SPF: 0
55+
ENABLE_SRS: 0
56+
ENABLE_QUOTAS: 0
57+
ODOO_RECEIVING_DOMAINS: manmanufacturing.com
58+
entrypoint:
59+
- bash
60+
- -c
61+
- |
62+
cp -r /tmp/docker-mailserver-staging/ /tmp/docker-mailserver
63+
chmod 755 /tmp/docker-mailserver/create-config.sh
64+
/tmp/docker-mailserver/create-config.sh
65+
exec supervisord -c /etc/supervisor/supervisord.conf
66+
volumes:
67+
- ./mail-testing-config/docker-mailserver/:/tmp/docker-mailserver-staging/:ro
68+
- ./odoo/custom/src/odoo/addons/mail/static/scripts/odoo-mailgate.py:/tmp/odoo-mailgate.py:ro
69+
70+
email_client_fake:
71+
image: roundcube/roundcubemail
72+
environment:
73+
ROUNDCUBEMAIL_COMPOSER_PLUGINS: "texxasrulez/persistent_login"
74+
ROUNDCUBEMAIL_PLUGINS: "show_additional_headers,persistent_login,autocreate_identity"
75+
depends_on:
76+
- mailserver
77+
volumes:
78+
- ./mail-testing-config/roundcube/roundcube_user_settings.inc.php:/var/roundcube/config/config.inc.php:ro
79+
- ./mail-testing-config/roundcube/plugins/autocreate_identity:/var/www/html/plugins/autocreate_identity
4080

4181
smtpreal:
4282
image: ghcr.io/docker-mailserver/docker-mailserver:latest

devel.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ services:
6464
- --limit-time-real=9999999
6565
- --workers=0
6666
- --dev=reload,qweb,werkzeug,xml
67+
- --from-filter=manmanufacturing.com
6768

6869
db:
6970
extends:
@@ -90,6 +91,37 @@ services:
9091
networks: *public
9192
ports:
9293
- "127.0.0.1:18025:8025"
94+
environment:
95+
MP_SMTP_RELAY_HOST: &mailserver mailserver
96+
97+
mailserver:
98+
extends:
99+
file: common.yaml
100+
service: mailserver_fake
101+
networks:
102+
default:
103+
environment:
104+
ODOO_DB: *dbname
105+
USER_ID: 2
106+
MAILBOX_DOMAIN: *mailserver
107+
MAILBOX_USER: admin
108+
ADMIN_PASSWORD: admin
109+
SMTP_SERVICE_NAME: smtp
110+
111+
roundcube:
112+
extends:
113+
file: common.yaml
114+
service: email_client_fake
115+
networks: *public
116+
ports:
117+
- "127.0.0.1:18080:80"
118+
environment:
119+
ROUNDCUBEMAIL_USERNAME_DOMAIN: *mailserver
120+
ROUNDCUBEMAIL_DEFAULT_HOST: *mailserver
121+
ROUNDCUBEMAIL_SMTP_SERVER: *mailserver
122+
ROUNDCUBEMAIL_SMTP_PORT: 25
123+
volumes:
124+
- roundcube:/var/www/html:rw
93125

94126
wdb:
95127
image: docker.io/kozea/wdb
@@ -174,3 +206,4 @@ networks:
174206
volumes:
175207
filestore:
176208
db:
209+
roundcube:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
# Setup postfix/dovecot account
4+
echo "$MAILBOX_USER@$MAILBOX_DOMAIN|{PLAIN}$ADMIN_PASSWORD" >> /tmp/docker-mailserver/postfix-accounts.cf
5+
6+
# Set up client access to redirect outgoing from odoo (through mailpit) to dovecot
7+
: > /tmp/docker-mailserver/postfix-client-access.cf
8+
echo "/$SMTP_SERVICE_NAME/ REDIRECT $MAILBOX_USER@$MAILBOX_DOMAIN" >> /tmp/docker-mailserver/postfix-client-access.cf
9+
10+
# Setup postfix transport map
11+
: > /tmp/docker-mailserver/postfix-transport-map.cf
12+
## Mail coming from odoo is delivered to roundcube's mailbox in dovecot
13+
echo "$MAILBOX_USER@$MAILBOX_DOMAIN lmtp:unix:/var/run/dovecot/lmtp" >> /tmp/docker-mailserver/postfix-transport-map.cf
14+
## Mail for the receiving domains is handled by odoo's mailgate without being redirected to an alias
15+
for domain in $(echo "$ODOO_RECEIVING_DOMAINS" | tr ',' ' '); do
16+
echo "$domain odoo_mailgate:" >> /tmp/docker-mailserver/postfix-transport-map.cf
17+
done
18+
## Discard everything else
19+
echo "* discard:" >> /tmp/docker-mailserver/postfix-transport-map.cf
20+
21+
# Define the 'odoo_mailgate' service in master.cf
22+
# Note that we must do this in /etc/postfix/master.cf directly as docker-mailserver does not support
23+
# defining custom services in /tmp/docker-mailserver/postfix-master.cf
24+
echo "" >> /etc/postfix/master.cf
25+
echo "odoo_mailgate unix - n n - - pipe" >> /etc/postfix/master.cf
26+
echo " user=nobody argv=/usr/local/bin/odoo-mailgate-wrapper.sh" >> /etc/postfix/master.cf
27+
28+
# Setup Odoo mailgate script
29+
cp /tmp/odoo-mailgate.py /usr/local/bin/odoo-mailgate.py
30+
chmod 755 /usr/local/bin/odoo-mailgate.py
31+
echo '#!/bin/sh' > /usr/local/bin/odoo-mailgate-wrapper.sh
32+
echo "/usr/bin/python3 /usr/local/bin/odoo-mailgate.py -d $ODOO_DB -u $USER_ID -p $ADMIN_PASSWORD --host odoo --port 8069" >> /usr/local/bin/odoo-mailgate-wrapper.sh
33+
chmod 755 /usr/local/bin/odoo-mailgate-wrapper.sh
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
smtpd_client_restrictions =
2+
check_client_access regexp:/tmp/docker-mailserver/postfix-client-access.cf
3+
4+
transport_maps = texthash:/tmp/docker-mailserver/postfix-transport-map.cf
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
class autocreate_identity extends rcube_plugin
4+
{
5+
public $task = 'mail';
6+
7+
function init()
8+
{
9+
$this->add_hook('message_load', array($this, 'create_identity_from_message'));
10+
}
11+
12+
function create_identity_from_message($args)
13+
{
14+
// Only process if we have headers and it's a message object
15+
if (!isset($args['object']) || !isset($args['object']->headers)) {
16+
return $args;
17+
}
18+
19+
$rcmail = rcmail::get_instance();
20+
$user = $rcmail->user;
21+
22+
// Get existing identities
23+
$existing_emails = array();
24+
foreach ($user->list_identities() as $identity) {
25+
$existing_emails[] = strtolower($identity['email']);
26+
}
27+
28+
// Get To and Cc addresses
29+
$recipients = array();
30+
if (!empty($args['object']->headers->to)) {
31+
$recipients = array_merge($recipients, rcube_mime::decode_address_list($args['object']->headers->to));
32+
}
33+
if (!empty($args['object']->headers->cc)) {
34+
$recipients = array_merge($recipients, rcube_mime::decode_address_list($args['object']->headers->cc));
35+
}
36+
37+
foreach ($recipients as $recipient) {
38+
$email = $recipient['mailto'];
39+
if (!in_array(strtolower($email), $existing_emails)) {
40+
$user->insert_identity(array(
41+
'name' => $recipient['name'] ?: '',
42+
'email' => $email,
43+
'standard' => 0,
44+
'signature' => '',
45+
'html_signature' => 0
46+
));
47+
$existing_emails[] = strtolower($email);
48+
}
49+
}
50+
51+
return $args;
52+
}
53+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
// Always use HTML editor
3+
$config['htmleditor'] = 1;
4+
5+
// Reply above the quote
6+
$config['reply_mode'] = 1;
7+
8+
// Turn off SMTP authentication because we are using port 25
9+
// Unfortunately, we cannot set this via environment variables. See:
10+
// https://github.com/roundcube/roundcubemail-docker/blob/9fd84b3e4f7943c7b2046d0a443a39d1a702edf2/fpm/docker-entrypoint.sh#L177-#L188
11+
$config['smtp_user'] = '';
12+
$config['smtp_pass'] = '';

odoo/custom/src/addons.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
./spreadsheet:
1616
- spreadsheet_oca
1717
- spreadsheet_dashboard
18+
19+
./mail:
20+
- mail_composer_cc_bcc
21+
- mail_tracking

odoo/custom/src/repos.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
# Shallow repositories ($DEPTH_DEFAULT=1) are faster & thinner
55
# You may need a bigger depth when merging PRs (use $DEPTH_MERGE
66
# for a sane value of 100 commits)
7-
depth: $DEPTH_DEFAULT
7+
depth: 300
88
remotes:
9+
px-odoo: https://github.com/Pyxiris/odoo.git
910
ocb: https://github.com/OCA/OCB.git
1011
odoo: https://github.com/odoo/odoo.git
1112
openupgrade: https://github.com/OCA/OpenUpgrade.git
12-
target: odoo $ODOO_VERSION
13+
target: agg
1314
merges:
1415
- ocb $ODOO_VERSION
16+
- odoo $ODOO_VERSION
17+
- odoo refs/pull/241583/head # Backport improvements to the odoo-mailgate script in 19.0 to 18.0
1518

1619
./web:
1720
defaults:
@@ -25,3 +28,12 @@
2528
- px-web 18.0-web_dark_mode
2629
- px-web 18.0-web_responsive
2730
- px-web 18.0-web_theme_classic
31+
32+
./mail:
33+
defaults:
34+
depth: $DEPTH_DEFAULT
35+
remotes:
36+
oca-mail: https://github.com/OCA/mail.git
37+
target: agg
38+
merges:
39+
- oca-mail $ODOO_VERSION

0 commit comments

Comments
 (0)