Ruby-on-rails ArgumentError:发送消息需要 SMTP To 地址。设置消息 smtp_envelope_to、to、cc 或 bcc 地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18419611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:35:17  来源:igfitidea点击:

ArgumentError: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to , cc, or bcc address

ruby-on-railsruby-on-rails-4actionmailer

提问by bulleric

I got an rails 4 application with following mailer configuration:

我得到了一个带有以下邮件程序配置的 rails 4 应用程序:

config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { host: 'myhost.com' }
  config.action_mailer.perform_deliveries = true

  config.action_mailer.smtp_settings = {
    :enable_starttls_auto => true,
    :address            => 'smtp.myhost.com',
    :port               => 587,
    :domain             => 'myhost.com',
    :authentication     => :login,
    :enable_starttls_auto => false,
    :tls                  => false,
    :openssl_verify_mode  => 'none',
    :ssl => false,
    :user_name          => "myusername",
    :password           => "mypassword"
  }

Every time i try to send an mail with an testing mailer setup:

每次我尝试发送带有测试邮件程序设置的邮件时:

class TestMailer < ActionMailer::Base

  default :from => "[email protected]"

  def welcome_email
    mail(:to => "[email protected]", :subject => "Test mail", :body => "Test mail body")
  end
end

TestMailer.welcome_email.deliver

I got this exception:

我得到了这个例外:

ArgumentError: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to , cc, or bcc address.

ArgumentError:发送消息需要 SMTP To 地址。设置消息 smtp_envelope_to、to、cc 或 bcc 地址。

Is it possible that i forget something to set.? And i can't find an configuration option for "smtp_envelope_to"

有没有可能我忘记了要设置的东西。?我找不到“smtp_envelope_to”的配置选项

回答by Miotsu

The error message is not about the SMTP envelope, but about the sender:

错误消息不是关于 SMTP 信封,而是关于发件人:

An SMTP To address is required to send a message

发送邮件需要 SMTP To 地址

the rest is just a generic message. Something in your [email protected]is not working. Do you use a real, working address? If not, try with one.

其余的只是一个通用的信息。你的某些东西[email protected]不起作用。您使用真实的工作地址吗?如果没有,请尝试一个。

回答by cool_php

If you use sidekiq+actionmailer. Be careful, while sending email using hash. I was doing something like this MyWorker.perform_async("var1", {email: '[email protected]', var2: 'test1234'})

如果你使用 sidekiq+actionmailer。使用哈希发送电子邮件时要小心。我正在做这样的事情 MyWorker.perform_async("var1", {email: '[email protected]', var2: 'test1234'})

I banged my head for couple of hours, why it is throwing the above error. Because in the perform_menthod hash[:email] is nil. You need to use hash["email"] to receive the email. I do not know, the reason. But it helped me to get rid of this error.

我撞了几个小时,为什么它会抛出上述错误。因为在 perform_menthod 中 hash[:email] 为零。您需要使用 hash["email"] 来接收电子邮件。我不知道,原因。但它帮助我摆脱了这个错误。

回答by carp

Is :to => '[email protected]'how it is in your failing environment? If it's not a hardcoded email address, do make sure that a variable containing the to-address is not blank.

:to => '[email protected]'它是如何在发生故障的环境?如果它不是硬编码的电子邮件地址,请确保包含收件人地址的变量不为空。

You don't have to set Mail::Message#smtp_envelope_toexplicitly. It can guess it from its recipients, ie. Mail::Message#destinations(to + cc + bcc), but it doesn't seem to have any.

您不必Mail::Message#smtp_envelope_to明确设置。它可以从它的接收者那里猜出它,即。Mail::Message#destinations(to + cc + bcc),但它似乎没有。