2

I have a server running Centos 7 and docker. This server is inside a local network and is not used externally. I have a Python docker container running on the server from which I would like to send email to company email addresses (first.last@company.com).

I can do this from the Centos server without issue via echo "Test" | mail -s "Subject" first.last@company.com.

From the Python docker container, I can connect to the sendmail server but not send.

#test.py

import smtplib
s=smtplib.SMTP('172.17.0.1')  # this is the docker bridge network ip
s.sendmail('mailer@app','first.last@company.com','message')

The Python code above results in the following error,

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/smtplib.py", line 885, in sendmail
    raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'first.last@company.com': (550, b'5.7.1 <first.last@company.com>... Relaying denied. IP name lookup failed [172.17.0.3]')}

and the following lines in /var/log/maillog,

Mar  5 13:38:58 servername sendmail[29570]: 125LOmVY029570: ruleset=check_rcpt, arg1=<first.last@company.com>, relay=[172.17.0.3], reject=550 5.7.1 <first.last@company.com>... Relaying denied. IP name lookup failed [172.17.0.3]
Mar  5 13:38:58 servername sendmail[29570]: 125LOmVY029570: from=<mailer@app>, size=4, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=[172.17.0.3]

indicating that the check_rcpt (check recipient) rule was being violated. I looked this up and this rule is related to relaying mail.

At first I thought this was because the IP of my docker container could not pass a reverse DNS lookup on the host machine so that the host machine could tell if the sending domain matched the IP. So I created the DNS proxy from here which worked and allowed me to start my Python container with --hostname app and then get a successful return of ping app on the host machine.

But this still didn't work so I tried adding the entry 172.17 RELAY to /etc/mail/access and then hashing it to create /etc/mail/access.db and restarting sendmail. This also did not seem to work.

I've been trying other things as well, but I can't seem to get the check_rcpt to pass. Can anyone help me figure out how to configure the system to allow the server to relay emails from my docker container? Do I need to somehow allow relayed mail to send to address at @company.com?

Thank you very much for any help you can provide!

Matt
  • 43
  • 6

1 Answers1

0

OK, so the smart thing to do is to forget about sendmail and use the docker container bytemark/smtp to create a mail server and then connect and send from the python container.

Matt
  • 43
  • 6