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.
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.
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.
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...).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With