postfix-dovecot/README.md
2025-02-03 15:07:12 -05:00

73 lines
2.5 KiB
Markdown

# mail01
This repo details the configuration for [setting up your own email server](https://www.aih.app/2023/07/03/set-up-your-own-email-server-on-ubuntu-22-04/) on Ubuntu 22.04.
The above guide will take you through the steps required to set up your own email server. However, this repo contains sample configuration files to aid in the process. Remember to replace any instances of `moeny.ai` with your own domain name.
Also, note that the `/etc/postfix/virtual_alias` file will need to include all user emails individually to prevent the catchall from sending those user's mail to the addresses it lists.
See the below steps for setting up SMTP capabilities for your email server. These steps are not included in the linked guide, but they are included in the sample configuration files provided in this repo:
1. Create a dedicated SMTP user:
```bash
# Create user (no login shell needed)
sudo useradd -r -m -s /sbin/nologin smtp_user
# Set password for SMTP authentication
sudo passwd smtp_user
# Create mail directory for the user
sudo mkdir -p /home/smtp_user/Maildir/{cur,new,tmp}
sudo chown -R smtp_user:smtp_user /home/smtp_user/Maildir
sudo chmod -R 700 /home/smtp_user/Maildir
```
2. Make sure to add this user to `/etc/dovecot/dovecot-users` like below:
```bash
smtp_user@moeny.ai:{plain}smtp_user-password
```
3. Edit `/etc/postfix/main.cf` by setting the following lines to `encrypt` instead of `may`:
```bash
smtp_tls_security_level = encrypt
smtpd_tls_security_level = encrypt
```
4. Edit `/etc/postfix/master.cf` by uncommenting the following lines:
```bash
# For STARTTLS secure SMTP submission on port 587
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_auth_only=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# For SMTPS implicit SSL/TLS on port 465
smtps inet n - y - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
```
5. Restart Postfix and Dovecot
```bash
sudo systemctl restart postfix
sudo systemctl restart dovecot
```
6. Configure the end service you want to use with SMTP:
```bash
SMTP_HOST=mail01.moeny.ai
SMTP_PORT=587
SMTP_USERNAME=smtp_user@moeny.ai
SMTP_EMAIL=service@moeny.ai
SMTP_PASSWORD=smtp_user-password
```
7. Test the configuration by sending an email from the end service.