Developing and testing applications sometimes require you to go the "non-standard" way. A good example is when you have a web-application which has a mail function. The mails must correctly be sent but remember, this is just a test of the application and you don't want your users to get spammed with test mails.
A fake/dummy mail server comes in handy. A developer suggested MailCatcher, which looked good to me except that it's written in ruby and depends on gems which I didn't want to put on this system. At least not if I find something easier...
Then I came across Dummy-SMTP, a simple listener written in python (so no additional software to be installed on my Ubuntu test servers) just saving all the received mails as text files in a folder.
By default, Dummy-SMTP runs on port 25 which requires root privileges to start with and it also must be started from within the correct folder. I made some modifications for the following purposes:
In my case, I defined the listener port to be 1025 and defined an absolute path: /srv/Dummy-SMTP which I chose where to run the listener.
To install Dummy-SMTP either clone the original repository or my forked one:
git clone https://github.com/Napsty/Dummy-SMTP.git
chown -R appuser:appuser /srv/Dummy-SMTP
Once the repository was cloned, become "appuser" if you aren't already and launch the listen.py file:
appuser@app01-test:~$ /srv/Dummy-SMTP/listen.py &
Running fake smtp server on port 1025
Now I adapted the Postfix installation and defined that all mails should be relayed to this fake smtp server by setting the relayhost parameter:
cat /etc/postfix/main.cf|grep relayhost
relayhost = 127.0.0.1:1025
service postfix reload
From now on a mail sent from this server should be relayed to the dummy smtp server and be just stored as a text file in /srv/Dummy-SMTP/mails. Let's try this:
echo "Dummy SMTP Test" | mailx -s "Test" email@example.com
app01-test postfix/pickup: 3559024A6A: uid=0 from=
app01-test postfix/cleanup: 3559024A6A: message-id=<20160607120336.3559024A6A@app01-test.local>
app01-test postfix/qmgr: 3559024A6A: from=
app01-test postfix/smtp: 3559024A6A: to=
app01-test postfix/qmgr: 3559024A6A: removed
And let's check out the Dummy SMTP mail folder:
Received: by app01-test.local (Postfix, from userid 0)
id 3559024A6A; Tue, 7 Jun 2016 14:03:36 +0200 (CEST)
X-Mailer: mail (GNU Mailutils 2.99.98)
Date: Tue, 7 Jun 2016 14:03:36 +0200 (CEST)
From: root@nzzshop-app01-test (root)
Dummy SMTP Test
Neat! It worked.
The above mentioned Ruby alternative Mailcatcher has one nice feature though: The mails can be seen by browser. Well, this isn't very complicated either. The mail folder of the dummy smtp server is a given (/srv/Dummy-SMTP/mails) so by creating a simple "Alias" on the Apache running already on this test server, I was able to display all sent mails on the browser, too:
Alias /mails "/srv/Dummy-SMTP/mails/"
Require all granted
Options +FollowSymLinks +Indexes
service apache2 reload
Nothing fancy of course, but it works:
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Container Containers CouchDB DB DNS Database Databases Docker ELK ElasticSearch Elasticsearch Filebeat FreeBSD GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Icingaweb2 InfluxDB Internet Java KVM Kibana Kubernetes LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher SSL Security Shell SmartOS Solaris Surveillance SystemD TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder