📜 ⬆️ ⬇️

The simplest SMTP server for development

For the lazy and unwilling to mess around, it is suggested to blow the dust from the tambourine to configure exim4 / postfix / sendmail a simple mail collector written in Python [1] .

His job is to collect all mail sent to this fake smtp server and fold it into the specified / tmp / mails folder as files of letters with the order number nobody@mail.local.1.


Step # 1: Install nullmailer


In standard turnips should be nullmailer. If not, then swing , and then we install:
sudo apt-get install nullmailer 

')
Go to / etc / nullmailer and add in the remotes file:
 localhost smtp 


Restart:
 service nullmailer restart 


In Debian-like Linux, the queue of letters is in / var / spool / nullmailer / queue /

Step 2: Install fakemail


Download the fakemail script, unpack it. If standard, then run
 python setup.py install 
or copy the file fakemail.py where necessary.

Now I would like to make it run as a service, and not just hanging in the console.
To do this, create the file /etc/init.d/fakemail and paste the following code into it:
Hidden text
 #!/bin/sh set -e NAME=fakemail DAEMON=/usr/local/bin/$NAME.py DOPTIONS="--path=/tmp/mails" test -x "$DAEMON" || exit 0 PIDDIR=/var/run PIDFILE=$PIDDIR/$NAME.pid LANG=C export LANG . /lib/lsb/init-functions start_fakemail() { start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- $DOPTIONS >/dev/null 2>&1 & } stop_fakemail() { if [ -f "$PIDFILE" ]; then PID=`cat $PIDFILE` kill -2 $PID rm -f "$PIDFILE" fi } case "$1" in start) log_daemon_msg "Starting MTA" start_fakemail ;; stop) log_daemon_msg "Stopping MTA" stop_fakemail ;; restart) stop_fakemail start_fakemail ;; esac exit 0 



If you manually copied the file, then it may be worthwhile to edit the file in line 6, where is DAEMON, to replace the path to our Python file.

Making it run:
 sudo chmod +x /etc/init.d/fakemail 


Now you need to create (under the root) the mails folder in / tmp [2]
 sudo mkdir /tmp/mails 


And add references to the service during system shutdown:
 sudo ln -s /etc/init.d/fakemail /etc/rc0.d/K20fakemail sudo ln -s /etc/init.d/fakemail /etc/rc1.d/K20fakemail sudo ln -s /etc/init.d/fakemail /etc/rc6.d/K20fakemail 


If you need it to start automatically, add the following:
code to add to autorun
 sudo ln -s /etc/init.d/fakemail /etc/rc2.d/S20fakemail sudo ln -s /etc/init.d/fakemail /etc/rc3.d/S20fakemail sudo ln -s /etc/init.d/fakemail /etc/rc4.d/S20fakemail sudo ln -s /etc/init.d/fakemail /etc/rc5.d/S20fakemail 


We start the service:
 service fakemail start 


[1] The main material was found by reference , I just added the service.

[2] any other folder is possible, but then inside /etc/init.d/fakemail where DOPTIONS = you need to change your path - path = / path / to / folder

Source: https://habr.com/ru/post/242647/


All Articles