gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:20:10 26 4
gpt4 key购买 nike

我正在尝试从 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 获得输出。

最佳答案

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.

    关于docker - 在 docker 容器中运行时找不到 Sendmail 主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55068797/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com