Mail send via Relay host on Ubuntu Server

From WikiMLT
Revision as of 12:34, 1 August 2022 by Spas (talk | contribs) (Spas moved page Ubuntu Server Mail send via Relay host to Mail send via Relay host on Ubuntu Server without leaving a redirect)

Ref­er­ences

Sec­tion 1

безрамка

Source:

  • Su­pe­rUser: How do I change post­fix port from 25 to 587?
  • Note: With this con­fig­u­ra­tion, all mail must be sent us­ing your Gmail ad­dress as "From", un­less you have set­up your Gmail (Settings>Accounts and Im­port>) to "Send mail as" some oth­er, then you cold use these email ad­dress­es.


Ed­it /etc/postfix/main.cf as fol­low.

sudo nano /etc/postfix/main.cf
#Ap­ply
# This tells Postfix to hand off all messages to Gmail, and never do direct delivery.
relayhost = [smtp.gmail.com]:587

# This enables TLS (SMTPS) certificate verification, because Gmail has a valid one.
smtp_tls_security_level = verify
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache

# This tells Postfix to provide the username/password when Gmail asks for one.
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

In /​​​etc/​​​postfix/​​​sasl_​​​passwd, add your Gmail user­name and pass­word.

sudo nano /etc/postfix/sasl_passwd
#Ap­ply
[smtp.gmail.com]:587    user-name@gmail.com:app-password
# Note you must setup App Password at https://myaccount.google.com/u/0/apppasswords

Com­pile the sasl_​​​passwd file in­to a data­base and re­load Postfix's main con­fig­u­ra­tion.

sudo postmap /etc/postfix/sasl_passwd && sudo postfix reload