Postfix setup for Raspberry Pi 3B+ (non-dedicated mail server, fantasy FQDN)

0

Problem: Create a contact form that lets users of a website submit messages that are sent to an email. Use php's mail() and Postfix. Having trouble using/understanding Postfix? The setup must be incorrect - I can't get email to show up on an external mail server (echo "hello, world" | mail destemailhere@gmail.com).

Setup: Running Postfix on a non-dedicated Raspberry Pi 3B+ over a port forward without a registered domain name (dynamic DNS). See Postfix on hosts without a real Internet hostname and other sections of the README.html... I am not sure what applies here. I do not need Postfix to receive mail? Note: during Postfix setup I literally entered mail.example.com as the FQDN. From what I can tell it might be a thing to use smtp.gmail.com as an external MTA through Postfix? That is the tutorial I tried to follow... so I have the SASL files it describes. I have not done much else in terms of setup. Using telnet smtp.gmail.com 25 and telnet smtp.gmail.com 587 both get a timeout.

Config:

main.cf:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Raspbian)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, mail.example.com, raspberrypi, localhost.localdomain, localhost
relayhost = [smtp.gmail.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

# Enable SASL auth
smtp_sasl_auth_enable = yes
# Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous
# Directory of sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption
smtp_use_tls = yes
# Directory of ca-certs
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Also:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.9 (stretch)
Release:        9.9
Codename:       stretch
$ sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:587           0.0.0.0:*               LISTEN      31792/sendmail: MTA
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      31792/sendmail: MTA

References: There is a discussion about using a Raspberry Pi with sendmail here (I am not trying to use sendmail but maybe it is helpful to consider its setup).

A previous answer suggested that "configuring postfix to send mail using gmail looks promising. Most public email systems (gmail, outlook, etc) either don't allow you to smtp relay, or you need to configure for their security. Without that, spammers would completely inundate their mail servers!"

Any further thoughts are appreciated.

Ders

Posted 2019-07-23T00:41:43.150

Reputation: 3

If you can't use 25 or 587 then that's what's wrong. Maybe try 465 still; but make sure you understand the differences. – tripleee – 2019-07-31T12:17:47.120

@tripleee if it's the port number then how do I determine which ports are open? Isn't it more likely that the ping isn't making it to Google's server or my IP is getting blocked? – Ders – 2019-08-01T15:54:44.610

If ping doesn't work, it really doesn't tell you anything; they could simply be blocking ICMP. If you can't connect to 587, have you tried 465? These two are reasonably standard but which one you will have to find from Gmail's documentation or by experimenting. But if 587 is correct and you can't connect to it, that's what you need to figure out (is your ISP blocking it? Your firewall?) – tripleee – 2019-08-01T16:12:44.863

No answers