在 Docker 容器中配置 SMTP

当我通过 Helm charts 部署 Discourse 时

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-release bitnami/discourse

一切都按预期工作,但我无法修改 Docker 容器中的 SMTP 电子邮件配置。

当我尝试复制 这个 时,我进入容器并执行

cd /opt/bitnami/discourse/config

在这个目录中,我找到了 discourse.conf 文件,但我无法按说明修改它,例如,vi 不可用。

您有什么建议吗?

您可以在他们的论坛上提问。不过他们已经关闭了。

或者您可以进行标准安装,并在此处获得帮助。

您或许可以设置环境变量。您可以查看示例。

您好 @pfaffman,非常感谢您的意见。

我现在知道如何将环境变量引入 Bitnami Helm Chart

鉴于我的交易邮件提供商 Sendinblue 的 SMTP 凭据

您知道我需要传递给 Dsicourse 容器的环境变量是什么样的吗?

如果您尝试使用常规 Gmail 帐户发送邮件,则违反服务条款,并且(由于其他几个原因)将无法正常工作。

在以下链接中有一个 SMTP 环境变量的示例:

1 个赞

你好 @pfaffman @Falco

非常感谢你的输入。

我的环境变量看起来是这样的:

discourse:
  extraEnvVars:
    - name: DISCOURSE_SMTP_ADDRESS
      value: "smtp-relay.sendinblue.com"
    - name: DISCOURSE_SMTP_PORT
      value: "587"
    - name: DISCOURSE_NOTIFICATION_EMAIL
      value: "no-reply@my-domain.com"
    - name: DISCOURSE_SMTP_USER_NAME
      value: "my-email@googlemail.com"
    - name: DISCOURSE_SMTP_PASSWORD
      value: "my-pw"
    - name: DISCOURSE_SMTP_DOMAIN
      value: "my-domain.com"

之后容器就启动了。我尝试从管理面板向我的Gmail账户发送一封测试邮件。我收到了这个:

所以目前它还没有起作用。

这是Discourse容器的日志:

Processing by Admin::UsersController#show as JSON
  Parameters: {"id"=>"1"}
Completed 200 OK in 1978ms (Views: 0.6ms | ActiveRecord: 0.0ms | Allocations: 195416)
Started GET "/groups/search.json" for 10.0.0.50 at 2022-08-10 11:55:05 +0000
Processing by GroupsController#search as JSON
Completed 200 OK in 1189ms (Views: 0.5ms | ActiveRecord: 0.0ms | Allocations: 133325)
Started GET "/admin/email.json" for 10.0.0.50 at 2022-08-10 11:55:17 +0000
Processing by Admin::EmailController#index as JSON
Completed 200 OK in 23ms (Views: 1.2ms | ActiveRecord: 0.0ms | Allocations: 864)
Started POST "/admin/email/test" for 10.0.0.50 at 2022-08-10 11:55:20 +0000
Processing by Admin::EmailController#test as */*
  Parameters: {"email_address"=>"test@gmail.com"}
Completed 422 Unprocessable Entity in 20ms (Views: 1.1ms | ActiveRecord: 0.0ms | Allocations: 2037)
Started GET "/about.json" for 10.0.0.47 at 2022-08-10 11:55:46 +0000
Processing by AboutController#index as JSON
Completed 200 OK in 67ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 9503)
Started GET "/site/basic-info.json" for 10.0.0.47 at 2022-08-10 11:55:46 +0000
Processing by SiteController#basic_info as JSON
Completed 200 OK in 254ms (Views: 0.5ms | ActiveRecord: 0.0ms | Allocations: 33103)
Started GET "/site/basic-info.json" for 10.0.0.47 at 2022-08-10 11:55:47 +0000
Processing by SiteController#basic_info as JSON
Completed 200 OK in 80ms (Views: 0.8ms | ActiveRecord: 0.0ms | Allocations: 4260)

你知道我还能做些什么吗?

您可以进入正在运行的容器并执行

message = TestMailer.send_test("test@gmail.com")
Email::Sender.new(message, :test_message).send

并检查将抛出的异常以获取线索。

1 个赞

这是从第一行获取的内容

bash: syntax error near unexpected token `('

您需要先进入 rails 控制台。转到 Discourse 目录并输入 rails c

1 个赞

然后我得到这个

root@discourse-69c7f5475c-h9qf5:/opt/bitnami/discourse# rails c
bash: rails: command not found
root@discourse-69c7f5475c-h9qf5:/opt/bitnami/discourse# ls
Brewfile         Gemfile.lock  adminjs  config.ru                  docs                 lefthook.yml  package.json             plugins  test            yarn.lock
CONTRIBUTING.md  LICENSE.txt   app      d                          images               lib           passenger.3000.pid.lock  public   tmp
COPYRIGHT.md     README.md     bin      db                         install-imagemagick  licenses      passenger.8080.pid       script   translator.yml
Gemfile          Rakefile      config   discourse.sublime-project  jsapp                log           passenger.8080.pid.lock  spec     vendor

好的,我刚才运行了

RAILS_ENV=production bundle exec rails c

irb(main):002:0> message = TestMailer.send_test("test@gmail.com")
Traceback (most recent call last):
        2: from app/mailers/test_mailer.rb:7:in `send_test'
        1: from lib/email/build_email_helper.rb:8:in `build_email'
ArgumentError (:arguments expected to be an Array of individual string args)

还有,这里也不行:

root@discourse-69c7f5475c-h9qf5:/opt/bitnami/discourse# RAILS_ENV=production bundle exec rails c message = TestMailer.send_test("test@gmail.com")
bash: syntax error near unexpected token `('

我这里是不是有什么地方做错了?

奇怪,在我这里运行得很好:

[5] pry(main)> message = TestMailer.send_test("test@gmail.com")
  TranslationOverride Exists? (0.8ms)  SELECT 1 AS one FROM "translation_overrides" WHERE "translation_overrides"."locale" = 'en' AND "translation_overrides"."translation_key" = 'test_mailer.subject_template' LIMIT 1
  (0.2ms)  SELECT "translation_overrides"."translation_key", "translation_overrides"."value" FROM "translation_overrides" WHERE "translation_overrides"."locale" = 'en'
TestMailer#send_test: processed outbound mail in 259.9ms
=> #<Mail::Message:212740, Multipart: false, Headers: <From: "Discourse" <noreply@unconfigured.discourse.org>>, <Reply-To: "Discourse" <noreply@unconfigured.discourse.org>>, <To: test@gmail.com>, <Subject: [Discourse] Email Deliverability Test>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <X-Auto-Response-Suppress: All>, <Auto-Submitted: auto-generated>>

由于您使用的是 Bitnami 打包的 unsupported-install,因此在细微之处出现问题是意料之中的。我们不支持此类安装,因此您需要联系他们的支持渠道:https://github.com/bitnami/charts/issues。

1 个赞

您好 @Falco,非常感谢您的回复。

您说的“不受支持的安装”是什么意思?我很乐意采用更多受支持的安装。:slight_smile:

那么,我仍然可以使用 Helm 图表完成所有事情吗?

你不能。只支持官方安装。请参阅Discourse 能否发布不需要引导的频繁 Docker 镜像?

上周我帮助某人进行了 K8s 安装。我和几位有才华的工程师花了 6 个多小时(但可能花了 10 个小时,不包括他们在我不在时花费的时间)才使用他们的工具完成。

我曾考虑创建应该从 Helm chart 启动的镜像,但尚未完成。如果您有预算,请通过私信或电子邮件与我联系,我或许可以提供帮助。

2 个赞