Mail send via Relay host on Ubuntu Server: Difference between revisions

From WikiMLT
m (Text replacement - "mlw-continue" to "code-continue")
 
Line 39: Line 39:
<syntaxhighlight lang="shell" line="1">
<syntaxhighlight lang="shell" line="1">
sudo postmap /etc/postfix/sasl_passwd && sudo postfix reload
sudo postmap /etc/postfix/sasl_passwd && sudo postfix reload
</syntaxhighlight>
== Test the configuration ==
<syntaxhighlight lang="shell" line="1">
echo "Tes is sent at: $(date)" | mail -s "Test subject" email@example.com
</syntaxhighlight>
</syntaxhighlight>


Line 46: Line 51:
* [[Gmail as SMTP Client (refs)]]
* [[Gmail as SMTP Client (refs)]]
* '''Note:''' With this configuration, all mail must be sent using your Gmail address as "From", unless you have setup your Gmail (<code>Settings</code>><code>Accounts and Import</code>>) to "Send mail as" some other, then you cold use these email addresses.
* '''Note:''' With this configuration, all mail must be sent using your Gmail address as "From", unless you have setup your Gmail (<code>Settings</code>><code>Accounts and Import</code>>) to "Send mail as" some other, then you cold use these email addresses.
* '''See also:''' [[szs:Ubuntu Server at Digital Ocean on LXD/LXC S3487#Mail%20Send|Ubuntu Server at DO # Mail_Send]]
<noinclude>
<noinclude>
<div id='devStage'>
<div id='devStage'>

Latest revision as of 12:45, 8 May 2023

Set­up Gmail as Re­lay host

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 ap­pli­ca­tion pass­word (see the ref­er­ences be­low).

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

Test the con­fig­u­ra­tion

echo "Tes is sent at: $(date)" | mail -s "Test subject" email@example.com

Ref­er­ences and Notes