I'm using Debian buster and I have installed postfix through
How I solved the connection time out and connection rejected issues:
In the /etc/postfix/main.cf you need to have
relayhost = [smtp.server.com]:PORT
relayhost = smtp.server.com:PORT
It took me a couple of hours to find this solution. You need the brackets.
How I solved the authentication issues
smtp_sasl_password_maps = static:smtp_username: smtp_password
Did the trick. Most probably this also can be explained by the configuration inside
/etc/postfix/sasl_passwd which was in the format
[smtp.server.com]:PORT username:password from which I created a hash map
postmap /etc/postfix/sasl_passwd that was set in
smtp_sasl_password_maps = /etc/postfix/sasl_passwd.db. I'm still not sure what is the proper format of the authentication entries inside the maps(with or without brackets, with or without port numbers).
How I solved "Sender address rejected: need fully-qualified address" error:
I still needed to reboot my computer after having changed
/etc/hostname to something that the SMTP server would accept.
How I sent an email through relay as firstname.lastname@example.org instead of email@example.com
If I try
echo "Test Email message body" | mail -s "Email test subject" firstname.lastname@example.org
The email comes to the account email@example.com as if it was sent from logged_on_user_linux@hostname_linux. To change the sender email to info@ instead of root@ I did the following:
echo "This is the main body of the mail" | mail -s "Some random subject" -a "From: firstname.lastname@example.org" email@example.com
How I let postfix relay all emails to the external SMTP
The external SMTP uses domain.com and it expects messages from users of this domain. Because of that, I needed to change
/etc/hostname to domain.com (although canonical address mapping might also have solved this issue without changing the hostname, I'm not sure as I'm somewhat new to postfix). It worked and emails started arriving with the sender being
firstname.lastname@example.org. But this setup impaired me from sending emails to email@example.com as postfix was keeping these messages to itself due to my
/etc/hostname also being domain.com. The workaround was to change
mydestination = $myhostname, domain.com, localhost, localhost.localdomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
myhostname = localhost
I'm not so sure what the value of
myhostname was before, but it probably pointed to domain.com one way or another.