0

我有一个 Rails 应用程序,它使用表单来收集消息详细信息并将消息通过电子邮件发送到我的 gmail/yahoo 帐户。

我已将此添加到 config/initializers 中的 setup_mail.rb 中:

ActionMailer::Base.smtp_settings = {  
      :address              => "smtp.gmail.com",  
      :port                 => 587,  
      :user_name            => "my_user",
      :password             => "my_pass", 
      :authentication       => "plain",  
      :enable_starttls_auto => true  
  }

并像这样将控制器用于 POST 路由:

def create
    @message = Message.new(params[:message])

    if @message.valid?
      NotificationsMailer.new_message(@message).deliver!
      redirect_to(root_path, :notice => "Message was successfully sent.")
    else
      flash.now.alert = "Please fill all fields."
      redirect_to('#')
    end
end

消息参数从表单中干净地接受,如下所示:

  Parameters: {"utf8"=>"✓", "authenticity_token"=>"4xgV0umvaTPzYxd18qdJq/GT7QCdXjrPTGR7D9R3AC4=", "message"=>{"name"=>"Deepak", "email"=>"deepakm.ccx@gmail.com", "subject"=>"Hi", "body"=>"Hi"}, "commit"=>"Send"}

无论我在设置中使用 Yahoo 凭据还是 Gmail 凭据,我都会不断收到相同的错误消息。我评论了 ActionMailer::Base.smtp_settings 中的所有设置,但仍然遇到此问题。这使我相信该问题可能与此代码之外的其他内容有关,但我一无所知。

-迪帕克

4

2 回答 2

0

虽然我仍然无法通过 ActionMailer 发送电子邮件,但我想我会发布一个替代方案。

https://github.com/nu7hatch/gmail

运行良好且更容易,因为您不需要使用任何配置文件。

谢谢。

于 2013-11-26T13:30:09.657 回答
0

你提到你的代码在config/initializers- 我们ActionMailer正在工作,它通过 Gmail 发送,除了我们把它放到我们的config/environments/developer.rb文件中:

  #Send Email In Development (Use Gmail's Servers)
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => "*****.co.uk",
      :user_name            => "******@gmail.com",
      :password             => "******",
      :authentication       => :plain,
      :enable_starttls_auto => true
  }
  config.action_mailer.default_url_options = {
      :host => "localhost:3000"
  }

也许您可以尝试复制并粘贴上面的代码?

于 2013-11-15T09:42:15.873 回答