How to configure postfix to send email via Gmail
3301 단어 Linux 관련
이 블로그는copy버전으로 제때에 업데이트되지 않을 수 있습니다. 최신 버전을 보려면 다음을 방문하십시오.
https://it.smallstrong.org/2019/05/how-to-configure-postfix-to-relay-email.html?view=classic
1. Why relay via Gmail?
Today it's very hard to set up an email server which can be trusted by other email servers. So even if you can configure a postfix server in a couple of minutes, you cannot send email successfully to other email servers because they don't trust you and deny emails sending from your own postfix server.
Another issue is most ISPs forbid TCP port 25 so your email server cannot send SMTP with port 25. Fortunately, 587 port which is used by Gmail is allowed.
Email relay is not a new tech but it works for the above situation. And Gmail server supports it for free! Almost all other email servers trust the Gmail server.
So now the sending process is:
local postfix server ---> Gmail server --->destination email server
The only issue is that the Gmail server will change the "from address"to the Gmail account before sending the email.
2. Gmail setup
The Gmail server can be connected as a relay host only if you already have a Gmail account used to log into the Gmail server.
For security reasons, the Gmail server by default refuses to be connected by non-authorized apps. In order to allow our postfix to connect to it, we need to manually configure our Gmail account's security level.
This means another hacker's app can also log in your Gmail account if he knows your password. So the best way is to create a new Gmail account dedicated used for relay purpose. Setting up a new Gmail account is easy and free!
3. Postfix installation and configuration
3.1 Install postfix
We use CentOS 7 in our test. To install required packages, do the below.
yum install postfix mailx cyrus-sasl cyrus-sasl-plain
3.2 create a password file
Then create a file/etc/postfix/sasl_passwd to store the Gmail account name and password.
vim/etc/postfix/sasl_passwd
[smtp.gmail.com]:587 [email protected]:password
To be secure, please change this file to be only accessible by its owner.
chmod 600/etc/postfix/sasl_passwd
Then compile this text file to binary format /etc/postfix/sasl_passwd.db
postmap/etc/postfix/sasl_passwd
3.3 Configure postfix as a SASL client
Next, we will modify/etc/postfix/main.cf to have the below.
vim/etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
Then restart postfix.
systemctl restart postfix
4 Send a test email
run:
date | mail -s 'Test relay via Gmail' [email protected]
5. Further thought
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
How to configure postfix to send email via GmailSo even if you can configure a postfix server in a couple of minutes, you cannot send email successfully to other email ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.