Postfix using /usr/sbin/sendmail
to send emails.
postfix can be configured as an SMTP-Client which called smtp-relay
method.
Authenticaiton for smtp-relay
using sasl
and we have to create a username/password file with plain auth information and create a Hash database from it. Postfix is using the hashed datapase:
Create Plain Username/Password File /etc/postfix/sasl_passwd
:
smtp.address.com username:password
Run this command to generate hashed database:
postmap etc/postfix/sasl_passwd
and this file will be created:
/etc/postfix/sasl_passwd.db
now, to Secure files run these commands:
chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
Edit the main configuration of postfix /etc/postfix/main.cf
and add these lines:
smtp_use_tls = no
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
# If this line is exists, overwite it
relayhost = webus.us
service postfix restart
echo "body of your email" | mail -s "This is a subject " -a "From:sender@address.com" myemail@example.com
Check logs in /var/log/syslog
file.
Sometimes we need to overwrite the sender address.
- Note: This Configs will affect on ALL outcoming Emails.
To that add below lines to /etc/postfix/main.cf
:
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps = regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check
Add /etc/postfix/sender_canonical_maps
:
/.+/ new-sender@address.com
Add /etc/postfix/header_check
:
/From:.*/ REPLACE From: new-sender@address.com