In some situations it’s needed if you have an internal mail server with a dynamic IP address, or simply one server hosting an application that have one form contact for example and a mail daemon listening in localhost, it can be very useful relay smtp traffic to the gmail servers, using smtp.gmail.com, and using a valid account autheticating via SASL. It’s very easy to implement but you have to configure some rules to talk with the gmail smtp servers.
- Edit postfix configuration:
|
# vi /etc/postfix/main.cf
#TLS parameters
smtpd_use_tls= yes
smtpd_tls_session_cache_database = btree:${data_directory} /smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory} /smtp_scache
smtp_tls_note_starttls_offer = yes
smtp_tls_policy_maps = hash : /etc/postfix/tls_policy
#Relay host configuration
relayhost = [smtp.gmail.com]:587
# SASL Configuration
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash : /etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
smtp_sasl_tls_security_options = noanonymous
|
- Add relay user to send the mail:
|
# vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 user@gmail.com:Password
# postmap /etc/postfix/sasl_passwd
|
- Config to force the use of ssl with the gmail smtp server:
|
# vi /etc/postfix/tls_policy
[smtp.gmail.com]:587 encrypt
# postmap /etc/postfix/tls_policy
|
- Restart postfix service:
|
# /etc/init.d/postfix restart
|
- If you have problems with mail traffic and see in mail.log file the next error:
Mar 29 15:10:36 www postfix/smtp[6927]: 7B39F1232BC: SASL authentication failed; cannot authenticate to server smtp.gmail.com[173.194.70.108]: no mechanism available
Probably you need to install the package
libsasl2-modules and restart postfix again.
Nhận xét
Đăng nhận xét