0

Using postfix I want to relay all my messages through an external smtp server.

I got connection time out and rejected errors even though I am able to connect to the SMTP server through telnet.

Then I got authentication errors. The server returned a "this server needs authentication" message.

Then I got a "Sender address rejected: need fully-qualified address" error.

Afterwards, I wanted to send an email as info@mydomain instead of root@mydomain.

Finally, when I tried to send messages to the same domain written in /etc/hostname but then messages weren't being relayed to the external SMTP.

I'll answer my own question to share the solutions I found and hopefully it will help others waste less time debugging.

1
  • We generally prefer not to compile too many separate issues into a single Q&A, it makes merging duplicates and linking related explanation harder. (e.g, your first issue is explained here) – anx Sep 29 '20 at 23:08
1

I'm using Debian buster and I have installed postfix through apt-get install.

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

Instead of

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 /etc/postfix/sasl_passwd.db using postmap /etc/postfix/sasl_passwd that was set in /etc/postfix/main.cf as 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 info@domain.com instead of root@domain.com

If I try

echo "Test Email message body" | mail -s "Email test subject" some@receipient.com 

The email comes to the account some@receipient.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: info@domain.com" some@receipient.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 root@domain.com. But this setup impaired me from sending emails to whatever@domain.com as postfix was keeping these messages to itself due to my /etc/hostname also being domain.com. The workaround was to change /etc/postfix/main.cf:

Instead of

mydestination = $myhostname, domain.com, localhost, localhost.localdomain, localhost

the following

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

and also

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.