在Docker容器中运行时找不到Sendmail主机

时间:2019-03-08 18:14:03

标签: docker sendmail alpine

我正在尝试从Docker容器发送电子邮件。我所能看到的最简单的单行代码来自earlier堆栈溢出答案:

docker run --rm --net="host" php:fpm-alpine sh -c 'echo "Subject: test" | sendmail -v your@mail.com'

我将your@mail.com更改为我的Gmail地址,然后运行命令。问题是我现在在终端中得到以下输出:

sendmail: recv:'220 mail.example.com ESMTP ready'
sendmail: send:'EHLO linuxkit-025000000001'
sendmail: recv:'250 mail.example.com'
sendmail: linuxkit-025000000001: Host not found

我需要做些什么才能使简单的示例邮件通过?

我想我已经关闭了,因为我从sendmail中获取了输出。

1 个答案:

答案 0 :(得分:1)

Sendmail试图通过位于以下地址的SMTP服务器中继电子邮件: mail.example.com 。这是此图像上sendmail的内置默认配置。

您要执行的操作是为sendmail传递google SMTP配置,如下所示:

echo "Subject: test" | sendmail -v -f your@mail.com -au<your-gmail-account> -ap<your-gmail-password> -H 'openssl s_client -quiet -tls1 -connect smtp.gmail.com:465' your@mail.com

一个实际的例子:

  • gmail帐户:your@gmail.com
  • gmail密码:123456

会是这样的:

echo "Subject: test" | sendmail -v -f your@mail.com -auyour@gmail.com -ap123456 -H 'openssl s_client -quiet -tls1 -connect smtp.gmail.com:465' your@mail.com

发送邮件-帮助

作为参考,这里是sendmail --help。您可以从与之配合使用的图像中获取它:

docker run --rm php:fpm-alpine sendmail --help
BusyBox v1.29.3 (2019-01-24 07:45:07 UTC) multi-call binary.

Usage: sendmail [-tv] [-f SENDER] [-amLOGIN 4<user_pass.txt | -auUSER -apPASS]
                [-w SECS] [-H 'PROG ARGS' | -S HOST] [RECIPIENT_EMAIL]...

Read email from stdin and send it

Standard options:
        -t              Read additional recipients from message body
        -f SENDER       For use in MAIL FROM:<sender>. Can be empty string
                        Default: -auUSER, or username of current UID
        -o OPTIONS      Various options. -oi implied, others are ignored
        -i              -oi synonym, implied and ignored

Busybox specific options:
        -v              Verbose
        -w SECS         Network timeout
        -H 'PROG ARGS'  Run connection helper. Examples:
                openssl s_client -quiet -tls1 -starttls smtp -connect smtp.gmail.com:25
                openssl s_client -quiet -tls1 -connect smtp.gmail.com:465
                        $SMTP_ANTISPAM_DELAY: seconds to wait after helper connect
        -S HOST[:PORT]  Server (default $SMTPHOST or 127.0.0.1)
        -amLOGIN        Log in using AUTH LOGIN (-amCRAM-MD5 not supported)
        -auUSER         Username for AUTH
        -apPASS         Password for AUTH

If no -a options are given, authentication is not done.
If -amLOGIN is given but no -au/-ap, user/password is read from fd #4.
Other options are silently ignored; -oi is implied.
Use makemime to create emails with attachments.