08.21.2019
Catch all mail using rainloop and postfix on Ubuntu
Sometime you do not want email to delivery outside for development purpose. This article will show you how to forward all mail to local user using rainloop, postfix, dovecot and nginx
I made this guide using Ubuntu 18.04, if you are using earlier release of Ubuntu you can also try it
First, install postfix, dovecot and postfix-prce
apt install vim postfix dovecot-imapd postfix-prce
Create new user call catchall (or what ever you want)
useradd -m catchall
Create password for new user (which use for loggin rainloop on future step)
passwd catchall
Install rainloop
cd /usr/share/nginx/html
mkdir rainloop
curl -sL https://repository.rainloop.net/installer.php | php
cd /var/www/html
ln -s /usr/share/nginx/html/rainloop
Configure dovecot
vim /etc/dovecot/conf.d/10-mail.conf
Replace mail_location as below
mail_location = maildir:/home/%u/Maildir
Configure Postfix
Change postfix config file
cd /etc/postfix
mv main.conf main.conf.org
mv main.conf.proto main.conf
Edit postfix config file
vim /etc/postfix/main.conf
uncomment
home_mailbox = Maildir/
uncomment
alias_maps = hash:/etc/aliases
then add aliases.regexp as below
alias_maps = hash:/etc/aliases, pcre:/etc/aliases.regexp
uncomment
alias_database = hash:/etc/aliases
Near the end of config file we will see some blank variable, please fill it like below
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
## comment out
#sample_directory
readme_directory = /usr/share/doc/postfix-2.10.1/README.Debian
## add new line for transport_maps
transport_maps = pcre:/etc/postfix/transport_maps
Create aliases.regexp
vim /etc/aliases.regexp
add below content
/(?!^root$|^catchall$)^.*$/ catchall
create transport.db
if transport file does not available please create it or skip if it already in /etc/postfix
touch /etc/postfix/transport
then run
postmap /etc/postfix/transport
now create transport_maps file
vim /etc/postfix/transport_maps
add below content
/^.*@.*$/ local
Comment out some line from master.conf file
Please comment out all of below config
maildrop
uucp
ifmail
bsmtp
scalemail-backend
mailman
change postmaster to our user
vim /etc/aliases
change postmaster from root to catchall
postmaster: catchall
Create aliases.db
postalias /etc/aliases
Start service
service postfix start
service dovecot start
Configure Rainloop
Access http://yourip/rainloop/?admin
Default rainloop account and password is admin/12345
In domain tab, delete all domain from list and add new localhost domain like below image
Click Add button
In login tab, add default domain as localhost
now login to rainlop user by url http://yourip/rainloop
input email as: catchall
input password as you create at early step
Test sending email
echo "this is a test message" | mailx -s 'this is a test
subject' [email protected]
Check your rainloop inbox to make sure you receive new email
if not, please check in mail log
tail -fn 100 /var/log/mail.log
if you see that all mail was send to root@localhost, do forward them
echo "root: catchall@localhost" >> /etc/aliases
&& newaliases
If you got command not found please install mailutils
apt install mailutils
Hope this help
If you have any problem, please leave me a line below