Attempt to implement personal mail server using python + aiosmtpd
Clone the project:
git clone git@github.com:denself/simple_mail_server.git
cd simple_mail_serverBefore running server, create virtual environment:
python3.6 -m venv venv
source venv/bin/activateYou might need to install venv before running this commands:
apt install python3.6-venvAnd install all requirements:
pip install -r requirements.txtServer support two optional settings, that cen be changed using environment variables:
SMTP_HOST defines host, on which server accepts connections. * for all.
Keep in mind, that if you setting SMTP_HOST=::1, that you should setup DNS
record that supports IPv6.
SMTP_PORT defines servers port. Default ports for SMTP are 25, 2525, 587 and
465, 25, 587, 2526 for Secure SMTP
SSL_KEYS path to ssl keys. Example:
SSL_KEYS=/path/to/keymean that there should exist files key.pem and key.crt in directory
/path/to/
To start server just run:
./main.pyTo properly handle incoming mail, two DNS record necessary:
- One
ARecord, that points to your mail server
mx.example.com A 1.2.3.4
- Another on
MXrecord, that points to previousArecord.
example.com MX mx.example.com
TODO: SPF/DKIM/DMARC records https://www.namecheap.com/support/knowledgebase/article.aspx/317/2237/how-do-i-add-txtspfdkimdmarc-records-for-my-domain
Install supervisor:
apt install supervisorCopy file supervisor.ini to you supervisor's conf.d directory:
cp supervisor.conf /etc/supervisor/conf.d/smtp_server.confEdit all variables to match your environment.
Start server:
supervisorctl reread
supervisorctl update
supervisorctl start smtp-server