I would like to send a mail to a gmail address:
echo "This is the body of the email" | mail -s "This is the subject line" [email protected]
That is what I see in the logs
connect to gmail-smtp-in.l.google.com[142.250.27.27]:25: Connection refused
connect to gmail-smtp-in.l.google.com[2a00:1450:4025:401::1a]:25: Network is unreachable
connect to alt1.gmail-smtp-in.l.google.com[2a00:1450:4025:c03::1a]:25: Network is unreachable
connect to alt1.gmail-smtp-in.l.google.com[142.251.9.27]:25: Connection refused
connect to alt2.gmail-smtp-in.l.google.com[142.250.150.27]:25: Connection refused
Apr 9 20:04:02 ubuntu postfix/smtp[157056]: 228717CAA0: to=<[email protected]>, relay=none, delay=0.22, delays=0.09/0.09/0.04/0, dsn=4.4.1, status=deferred (connect to alt2.gmail-smtp-in.l.google.com[142.250.150.27]:25: Connection refused)
tried to test this destination with netcat and the result was the same:
ubuntu@ubuntu:~$ nc -zvn 142.251.9.27 25
nc: connect to 142.251.9.27 port 25 (tcp) failed: Connection refused
then I checked the port 587 with the following command - which went ok:
ubuntu@ubuntu:~$ openssl s_client -connect smtp.gmail.com:587 -starttls smtp
CONNECTED(00000003)
depth=2 C = US, O = Google Trust Services LLC, CN = GTS Root R1
verify return:1
depth=1 C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
verify return:1
depth=0 CN = smtp.gmail.com
verify return:1
so I tried to force postfix to use encryption according to this so modified the main.cf:
smtpd_tls_security_level=encrypt
smtp_tls_security_level=encrypt
but still trying to use port 25 which is blocked. So my question is that how can I force postfix to use different port from 25 to be able to send outgoing mails?