【问题标题】:ActionMailer acting different on production serverActionMailer 在生产服务器上的行为不同
【发布时间】:2026-02-01 23:05:03
【问题描述】:

我有一个类似这样的动作邮件方法:

def mail
 @receiver = User.where(status: 2).pluck(:email)
 mail(bcc:@receiver, to: "username@gmail.com")
end 

application.yml 看起来像这样:

SMTP_ADDRESS: 'smtp.gmail.com'
SMTP_PORT: 587
SMTP_HOST: 'localhost:3000'
SMTP_DOMAIN: 'localhost:3000'
SMTP_USERNAME: 'user@gmail.com'
SMTP_PASSWORD: 'xxxxx'
SUPER_ADMIN_EMAIL: 'super_admin@mailinator.com'

developmet.rb 如下所示:

config.action_mailer.asset_host = ENV["SMTP_HOST"]
  # config.action_mailer.delivery_method = :letter_opener
  config.action_mailer.raise_delivery_errors = false

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    #Enter the smtp provider here ex: smtp.mandrillapp.com
    address: ENV["SMTP_ADDRESS"],
    port: ENV['SMTP_PORT'].to_i,
    #Enter the smtp domain here ex: vendaxo.com
    domain: ENV["SMTP_DOMAIN"],
    #Enter the user name for smtp provider here
    user_name: ENV["SMTP_USERNAME"],
    #Enter the password for smtp provider here
    password: ENV["SMTP_PASSWORD"],
    authentication: 'plain',
    enable_starttls_auto: true

接收者保存在密件抄送中,但“username@gmail.com”将能够看到密件抄送接收者。当我从本地主机发送邮件时,这工作正常。当接收者被发送电子邮件时,它们都在密件抄送中,并且一个'username@gmail.com'可以看到所有接收者。

但是当我在生产服务器上使用类似的 application.yml 配置更改主机和端口时,username@gmail.com 不会收到电子邮件BCCd 接收器。

【问题讨论】:

标签: ruby-on-rails email actionmailer


【解决方案1】:

我认为,如果您在 AWS EC2 上运行生产服务器(也可能是其他提供商),每次您对 application.yml 或任何其他共享文件进行一些更改时,您都需要重新启动应用服务器以应用更改的配置。在我的情况下,我不得不重新启动 PUMA,并且一封默认电子邮件开始获取 BCCd 电子邮件 ID。

【讨论】:

    最近更新 更多