0

I've a Docker container running on Debian (stretch). I had sendmail installed through apt-get install sendmail on the Docker container so that I can send emails from the container.

Here's how my Dockerfile look:

FROM php:5.6-apache
RUN apt-get update && \
  apt-get install -y sendmail && \
  apt-get clean

And I run some commands to update the host file:

host=$(hostname)
line=$(cat /etc/hosts |grep [1]27.0.0.1)
echo "$line localhost.localdomain $host" >> /etc/hosts

When I'm running the container on my local dev machine (Windows) through Virtualbox, I can send emails directly using the sendmail command in bash without issues. I can receive those emails in my mailbox.

However, when I run the container on a cloud instance (in my case on Digital Ocean), running the same sendmail command in bash doesn't send emails. There are no errors or whatsoever. The sendmail command just returned as though the email was sent successfully, but I never receive it in my mailbox.

When I run mailq in the Docker container on my cloud instance, I could see the following error message:

Mon Jun 25 02:05 <www-data@localhost.localdomain> (Deferred: Connection timed out with alt4.gmail-smtp-in.l.goo)

There are no error messages in mailq in the same container when running on my local computer.

Shouldn't the Docker container work the same even on a different host machine? Why does sendmail work when running in the container on my local computer, but not when running it on a cloud instance?

1

Can you connect to any server on port 25 using other utilities?

You can test it easily with 'telnet' against the Google server that appears on the error message. If you can reach it you should see something like this:

$ telnet alt4.gmail-smtp-in.l.google.com 25
Trying 74.125.195.26...
Connected to alt4.gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP z2-v6si2977862pfz.241 - gsmtp

If you can't, you should check any firewall you might have. Digital Ocean have their own firewall integrated on the control panel. If it's not correctly configured you may have port 25 filtered.

  • I can't telnet to alt4.gmail-smtp-in.l.google.com 25. I got a timeout. But I don't think Digital Ocan blocks my port 25. In my firewall settings, I've also allowed all outbound traffic on port 25. – xenon Jul 8 '18 at 15:32
  • What about other mail servers? If you can connect to any other server on port 25 you can discard a filter on your end. – RixzZ Jul 9 '18 at 13:08

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.