59 lines
1.4 KiB
Bash
59 lines
1.4 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# source:
|
||
|
# https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-22-04
|
||
|
#
|
||
|
|
||
|
set your_domain="abc.com"
|
||
|
|
||
|
sudo apt update
|
||
|
sudo apt install mailutils
|
||
|
|
||
|
# sudo vim /etc/postfix/main.cf
|
||
|
#
|
||
|
# masquerade_domains = {your_main_domain}
|
||
|
# inet_interfaces = loopback-only
|
||
|
|
||
|
# restart service
|
||
|
sudo systemctl restart postfix
|
||
|
|
||
|
# to test smtp is working:
|
||
|
# echo "This is the body of the email" | mail -s "This is the subject line" your_email_address
|
||
|
|
||
|
# to add email forwarding:
|
||
|
# sudo vim /etc/aliases
|
||
|
#
|
||
|
# postmaster: root
|
||
|
# root: your_email_address
|
||
|
#
|
||
|
# for the change to take effect run:
|
||
|
# sudo newaliases
|
||
|
#
|
||
|
# to test email forwarding:
|
||
|
# echo "This is the body of the email" | mail -s "This is the subject line" root
|
||
|
|
||
|
|
||
|
|
||
|
# Enable SMTP Encryption
|
||
|
#
|
||
|
# install certbot:
|
||
|
sudo apt install certbot
|
||
|
|
||
|
# make sure server port 80 is open underfirewall
|
||
|
# if you are using on server firewall "ufw", do:
|
||
|
# sudo ufw allow 80
|
||
|
|
||
|
# get cert
|
||
|
sudo certbot certonly --standalone --rsa-key-size 4096 --agree-tos --preferred-challenges http -d $your_domain
|
||
|
|
||
|
# sudo vim /etc/postfix/main.cf
|
||
|
#
|
||
|
# smtpd_tls_cert_file=/etc/letsencrypt/live/your_domain/fullchain.pem
|
||
|
# smtpd_tls_key_file=/etc/letsencrypt/live/your_domain/privkey.pem
|
||
|
|
||
|
# restart service
|
||
|
# sudo systemctl restart postfix
|
||
|
|
||
|
# test
|
||
|
# echo "This is the body of an encrypted email" | mail -s "This is the subject line" root
|