Setting up mailserver with relay host

postfix

So the port 25 on my mailserver is blocked and I'm now trying to set up my mail server with a SMTP relay to send mail with dynu.com. But i keep getting the error messages bellow when i try to send a mail from the
terminal window.

In master.cf I have set the following

465 inet n - n - - smtpd

In main.cf I have set this

myhostname = rajohan.no
mydestination = localhost, rajohan.no, localhost.rajohan.no
mynetworks = 127.0.0.0/8 192.168.0.0/24 [::ffff:127.0.0.0]/104 [::1]/128

smtpd_sasl_auth_enable = yes
smtpd_sasl_password_maps = hash:/etc/postfix/sasl_password

relayhost = [relay.dynu.com]:465
smtpd_generic_maps = hash:/etc/postfix/generic

In sasl_password i have

relay.dynu.com
relay@relay.rajohan.no mypassword

In generic i have

mail@rajohan.no         mail@rajohan.no
postbot@rajohan.no      postbot@rajohan.no
webmaster@rajohan.no    webmaster@rajohan.no
postmaster@rajohan.no   webmaster@rajohan.no
root@rajohan.no         webmaster@rajohan.no
root@mail.rajohan.no    webmaster@rajohan.no
abuse@rajohan.no        webmaster@rajohan.no
hostmaster@rajohan.no   webmaster@rajohan.no

Dec 19 22:22:49 rajohan dovecot: imap-login: Login:
user=, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1,
mpid=30452, secured, session=<6DQx6LhgdJZ/AAAB>

Dec 19 22:22:49 rajohan dovecot: imap(mail@rajohan.no): Logged out in=50 out=490

Dec 19 22:22:57 rajohan postfix/pickup[30405]: AEF3884669: uid=0
from=

Dec 19 22:22:57 rajohan postfix/cleanup[30461]: warning:
connect to Milter service unix:/opendkim/opendkim.sock: No such file or directory

Dec 19 22:22:57 rajohan postfix/cleanup[30461]: AEF3884669: message-id=<20171219222257.AEF3884669@rajohan.no>

Dec 19 22:22:57 rajohan postfix/qmgr[30406]: AEF3884669: from=, size=284, nrcpt=1 (queue active)

Dec 19 22:22:57 rajohan postfix/smtp[30467]: SMTPS wrappermode (TCP port 465) requires setting "smtp_tls_wrappermode = yes", and "smtp_tls_security_level = encrypt" (or stronger)

Dec 19 22:22:59 rajohan postfix/smtp[30467]: AEF3884669: to=rajohan1@gmail.com>, relay=relay.dynu.com[199.233.237.19]:465, delay=23, delays=21/0.08/1.3/0.33, dsn=5.0.0, status=bounced (host relay.dynu.com[199.233.237.19] said: 530 SMTP authentication is
required. (in reply to RCPT TO command))

Dec 19 22:22:59 rajohan postfix/cleanup[30461]: BFE7E84668: message-id=<20171219222259.BFE7E84668@rajohan.no>

Dec 19 22:22:59 rajohan postfix/qmgr[30406]: BFE7E84668: from=<>, size=2190, nrcpt=1 (queue active)

Dec 19 22:22:59 rajohan postfix/trivial-rewrite[30462]: warning: do not list domain rajohan.no in BOTH mydestination and virtual_mailbox_domains

Dec 19 22:22:59 rajohan postfix/bounce[30470]: AEF3884669: sender non-delivery notification: BFE7E84668

Dec 19 22:22:59 rajohan postfix/qmgr[30406]: AEF3884669: removed

Dec 19 22:22:59 rajohan postfix/local[30471]: BFE7E84668: to=, orig_to=, relay=local, delay=0.06, delays=0.03/0/0/0.03, dsn=5.1.1, status=bounced (unknown user: "webmaster")

Dec 19 22:22:59 rajohan postfix/qmgr[30406]: BFE7E84668: removed

Best Answer

Your sasl_password file should be formatted like this and match that of the relayhost directive:

[host]:Port USERNAME:PASSWORD

So, your's would look like this:

[relay.dynu.com]:465 relay@relay.rajohan.no:mypassword

Then you need to hash the file: sudo postmap /etc/postfix/sasl_password

Now, you have a file created: /etc/postfix/sasl_password.db

Change the following directives in your main.cf (remove the d):

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password

Don't forget to restart postfix.

Configuring SASL authentication in the Postfix SMTP/LMTP client