电子邮件不能在Linux容器中工作

我无法从我的容器发送电子邮件。 我运行:

apt-get update apt-get install mailutils echo "Testing the mail" | mail -s "Test mail" info@example.com 

…并没有电子邮件。

不知道这是否与Docker本身相关。 要从mail命令发送电子邮件,您需要本地SMTP中继/服务器。

这意味着你将不得不在你的容器中安装这样的继电器。 你可以设置Postfix或者,如果你想要一个更简单的解决scheme, ssmtp

 apt-get -y install ssmtp 

对于/etc/ssmtp/ssmtp.conf使用以下configuration:

 root=your@email.com # Example for relaying to Gmail servers mailhub=smtp.gmail.com:587 AuthUser=myaddress@gmail.com AuthPass=my_gmail_password UseTLS=YES UseSTARTTLS=YES 

理想情况下,如果您需要定期使用mail命令从您的容器发送电子邮件,则应该通过创build自定义的Docker镜像来设置SMTP中继。 但是这可能意味着设置一个可以运行多个进程的容器(SMTP中继,你的应用程序…)。