Setting Up Postfix for SMTP
Install and Configure Postfix
-
Install Postfix
sudo apt update sudo apt install postfix -y
-
Configure Postfix
Edit the Postfix main configuration file:
sudo nano /etc/postfix/main.cf
Add or modify the following configurations:
relayhost = [smtp.example.in]:1025 # Specify your SMTP relay host and port # Add user and password variables if needed
-
Restart Postfix to Apply Changes
sudo systemctl restart postfix
-
Test Email Functionality
Send a test email to verify the configuration:
echo "Test email body" | mail -s "Test email subject" [email protected]
External SMTP Configuration (e.g., Gmail)
-
Set Up Authentication for External SMTP
Edit the
sasl_passwd
file to store your SMTP credentials:sudo nano /etc/postfix/sasl_passwd
Add your SMTP credentials:
[smtp.gmail.com]:587 [email protected]:xyz
Important: Replace
[email protected]
andxyz
with your actual Gmail username and app password. -
Secure the
sasl_passwd
FileSet the appropriate permissions and create a hashed database:
sudo chmod 600 /etc/postfix/sasl_passwd sudo postmap /etc/postfix/sasl_passwd
-
Configure Postfix for External SMTP
Edit the Postfix configuration file:
sudo nano /etc/postfix/main.cf
Add or modify the following configurations:
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = jira-server alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases mydestination = $myhostname, jira-dc10-server, jira-server, localhost.localdomain, localhost relayhost = [smtp.gmail.com]:587 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = all smtp_sasl_auth_enable = yes smtp_sasl_security_options = noanonymous smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_use_tls = yes smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
-
Restart Postfix to Apply Changes
sudo systemctl restart postfix
Additional Resources
- For more detailed external SMTP configuration, refer to resources such as PhoenixNAP's Postfix SMTP Guide (opens in a new tab).
This guide should help you configure Postfix for both local and external SMTP servers. Make sure to replace placeholder values with your actual server details and credentials.