【问题标题】:Actionmailer Rails 3动作邮件程序 Rails 3
【发布时间】:2015-03-24 20:53:52
【问题描述】:

我在我的网站上添加了一个联系表格,但遇到了一个问题,当我发送消息时,我收到了我的 Flash 消息,“成功发送”,但是电子邮件从未到达我的收件箱。我目前处于开发模式,我的 app/config 文件看起来像这样

   class Application < Rails::Application

   ActionMailer::Base.delivery_method = :smtp
   ActionMailer::Base.perform_deliveries = true
   ActionMailer::Base.raise_delivery_errors = true
   config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port    => 587,
    :domain  => "gmail.com",
    :user_name  => "myemail@gmail.com",
    :password   => "example",
    :authentication => :plain,
    :enable_starttls_auto => true
      }

     config.action_mailer.default_url_options = {
     :host => "gmail.com"
      }

我的联系人Controller是这样的

      def new
       @message = Message.new
      end

     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."
     render :new
     end
    end 

     end

最后是我的通知邮件程序

      class NotificationsMailer < ActionMailer::Base
      default :from => "myemail@gmail.com"
      default :to => "myemail@gmail.com"

     def new_message(message)
     @message = message
     if message.file
      attachment_name = message.file.original_filename
      attachments[attachment_name] = message.file.read
     end
     mail(:subject => "[myemail@gmail.com] #{message.subject}")
    end
     end

我是否在这里遗漏了任何明显的东西,因为我已经在另一个运行良好的站点中实现了这个,只是无法弄清楚发生了什么

任何帮助表示赞赏

【问题讨论】:

  • 你分析过日志吗?搜索 Sent mail to [RECEIVER'S EMAIL] 之类的内容以检查邮件是否发送成功。如果您发现类似的日志,请检查您的垃圾邮件文件夹是否包含邮件?
  • 我知道这是一个老问题,您可能已经继续前进,但我首先要验证您是否可以使用控制台成功发送电子邮件。在那里实例化并发送电子邮件。

标签: ruby-on-rails-3 actionmailer


【解决方案1】:

我知道你在 app/config.rb 中设置了它,但我会确保 config.action_mailer.perform_deliveries 不会在你的 config/environments/development.rb 中被覆盖

【讨论】:

  • 感谢您的回答,我的配置/环境/开发中没有任何内容可以覆盖,仍然无法正常工作
猜你喜欢
  • 1970-01-01
  • 2011-08-22
  • 1970-01-01
  • 2014-11-09
  • 2012-11-22
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多