I'm trying to send e-mail through a remote vm running postfix
as an smtp server.
However, I'm receiving a 554 - Relay access denied
error when sending the rcpt
cmd.
(554, b'5.7.1 <xxxxx@xyz.org>: Relay access denied')
I understand that it is denying the e-mail address I'm attempting to set as a recipient, but I don't understand why.
The socket connection itself establishes fine, and I'm able to send a mail
cmd prior to attempting rcpt
.
Environment Details:
Host Machine:
Windows 7 machine / Language: Python 3.
Guest VM:
Docker container (Ubuntu) VM running
postfix
,ssh
-- with dhcp-assigned ip address10.35.50.166
.
This is the python
code running:
(on host machine):
import smtplib
server = smtplib.SMTP(host='10.35.50.166', port=8025)
server.mail('xxxxx@xyz.org')
(250, b'2.1.0 Ok')
server.rcpt('xxxxx@xyz.org')
(554, b'5.7.1 <xxxxx@xyz.org>: Relay access denied')
Running from the guest machine, the error does not occur:
import smtplib
server = smtplib.SMTP(host='localhost', port=8025)
server.mail('xxxxx@xyz.org')
(250, b'2.1.0 Ok')
server.rcpt('xxxxx@xyz.org')
(250, b'2.1.5 Ok')
Postfix' default configuration on Ubuntu allows relay access only on the local interface (i.e. localhost). When connecting on other interfaces (VM network), it requires SMTP authentication.
So you could either add authentication to your SMTP call or add your host ip to the allowed relay networks.
To achive the later, find the line in your /etc/postfix/main.cf
file that reads
mynetworks = 127.0.0.0/8
and change it to
127.0.0.0/8,10.0.0.0/8
Then reload postfix with
sudo postfix reload
Edit:
Alternatively, you could set the mynetworks_style
setting to
mynetworks_style = subnet