【问题标题】:Rails dont send email in dockerRails 不在 docker 中发送电子邮件
【发布时间】:2023-02-10 06:03:56
【问题描述】:

我需要帮助。

我尝试使用 Rails 和默认邮件服务发送电子邮件。在开发中一切正常,但在 dockerize 项目之后我得到错误:“错误的身份验证类型'plain'”。

---------------------- 我的 docker 文件 ---------------------- -

FROM ruby:3.1.2

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /app
WORKDIR /app


COPY Gemfile .
COPY Gemfile.lock .
RUN gem update bundler
RUN bundle install

COPY . .

ENV RAILS_ENV production

EXPOSE 3000

CMD rails server -b 0.0.0.0 -p 3000

---------------------- 我的.env 文件-------------------- --

SMTP_ADDRESS='smtp.gmail.com'
SMTP_PORT=587
SMTP_AUTHENTICATION='plain'
SMTP_USER_NAME='login'
SMTP_PASSWORD='password'

DATABASE_NAME='dbname'
DATABASE_USERNAME='dbuser'
DATABASE_PASSWORD='dbpassword'
DATABASE_PORT=5432
DATABASE_HOST='host.docker.internal'

---------------------- 我的production.rb文件-------------------- ---

config.action_mailer.delivery_method = :smtp
host = 'example.com' #replace with your own url
config.action_mailer.default_url_options = { host: host }


config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp

config.action_mailer.smtp_settings = {
:address              => ENV['SMTP_ADDRESS'],
:port                 => ENV['SMTP_PORT'],
:authentication       => ENV['SMTP_AUTHENTICATION'],
:user_name            => ENV['SMTP_USER_NAME'],
:password             => ENV['SMTP_PASSWORD'],
:enable_starttls_auto => true,
:openssl_verify_mode  => 'none' #Use this because ssl is activated but we have no certificate installed. So clients need to confirm to use the untrusted url.
}

【问题讨论】:

    标签: gmail


    【解决方案1】:

    我想也许您需要将 ENV 变量传递到 Dockerfile 中?或者如果你有一个 docker-compose 文件,把它传到那里

    【讨论】:

      猜你喜欢
      • 2011-10-25
      • 1970-01-01
      • 2014-07-11
      • 2014-12-31
      • 2013-05-21
      • 1970-01-01
      • 2015-05-02
      • 1970-01-01
      • 2017-01-17
      相关资源
      最近更新 更多