Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emails not working in Linux Containers

Tags:

docker

I'm having trouble sending emails from my containers. I run:

apt-get update
apt-get install mailutils
echo "Testing the mail" | mail -s "Test mail" [email protected]

...and no email.

like image 753
Batandwa Avatar asked Jun 07 '14 16:06

Batandwa


People also ask

Why mail not sending from Linux server?

The mail server could be propagating its DNS record, misspelled, or having resolution/network problems. This issue requires investigation of the mail server as a system administrator. As an alternative to the mail server's domain, you can also use the mail server's IP address.

How do I know if my email is working Linux?

Type "ps -e | grep sendmail" (without quotes) at the command line. Press the "Enter" key. This command prints a listing that includes all running programs whose name contains the text "sendmail." If sendmail is not running, there will be no results.


1 Answers

Not sure if this is related to Docker itself. To send an email from the mail command, you need a local SMTP relay/server.

That means that you would have to install such a relay in your container. You can setup Postfix or, if you want an easier solution, ssmtp

apt-get -y install ssmtp

And use the following configuration for /etc/ssmtp/ssmtp.conf:

[email protected]
# Example for relaying to Gmail servers
mailhub=smtp.gmail.com:587
[email protected]
AuthPass=my_gmail_password
UseTLS=YES
UseSTARTTLS=YES

Ideally, if you need to send emails from your containers using the mail command on a regular basis, you should setup your SMTP relay by creating your custom Docker image. But that would probably imply setting up a container that can run multiple processes (the SMTP relay, your application...).

like image 128
mbarthelemy Avatar answered Oct 17 '22 23:10

mbarthelemy