【问题标题】:Mailer not sending in railsMailer 没有在 Rails 中发送
【发布时间】:2014-01-28 12:00:05
【问题描述】:

我想在我的 Rails 应用程序中发送电子邮件,但我不知道为什么电子邮件没有发送到电子邮件目的地,而在我的日志中电子邮件发送。这是我在environment/development.rb 中的电子邮件发件人设置:

MyApp::Application.configure do

  config.cache_classes = false
  config.eager_load = false

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = false    
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load

  config.assets.debug = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :domain               => 'gmail.com',
    :user_name            => 'my_username',
    :password             => 'my_pass',
    :authentication       => 'plain',
    :enable_starttls_auto => true  }
end

这是我的UserMailer.rb

class UserMailer < ActionMailer::Base  
    def checkout(admin_email, email, ids, store_name)
        @email = email
        @seller = admin_email
        @store_name = store_name
        @orders = []
        @store = Store.where("name = ?", store_name).first

        ids.each do |f|
          @orders << Order.find(f) 
        end   
        mail(:to => "<#{email}>", :from => "<#{admin_email}>", :subject => "checkout confirmation")
      end
end

这是我的控制器中用于发送电子邮件的代码:

UserMailer.checkout(admin_email, email, ids, store.name).deliver

为什么这封电子邮件似乎已发送(根据日志)但未发送给收件人?

【问题讨论】:

  • 为什么你写的越来越少然后在你的邮件之前和之后签名删除它们。
  • 是的,改成mail(:to =&gt; email, :from =&gt; admin_email, :subject =&gt; "checkout confirmation")

标签: ruby-on-rails mailer


【解决方案1】:

如果您使用的是 gmail,请确保您的用户名字段实际上是:username@gmail.com 我遇到了类似的问题,一旦我更改了用户名,它就可以工作了

【讨论】:

    猜你喜欢
    • 2012-06-28
    • 2011-05-15
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 2015-08-23
    • 2012-07-25
    • 1970-01-01
    • 2019-10-29
    相关资源
    最近更新 更多