新手问题 Mailer 接收不到邮件

autumnwolf · 2014年05月12日 · 最后由 autumnwolf 回复于 2014年05月12日 · 2268 次阅读
Sent mail to william.hqs@gmail.com (4079.1ms)
Date: Mon, 12 May 2014 09:18:25 +0800
From: huqius@gmail.com
To: william.hqs@gmail.com
Message-ID: <5370216129765_37673fde1b883a0414227@Williams-MacBook-Pro.local.mail>
Subject: =?UTF-8?Q?=E5=A4=A9=E5=A4=A9=E5=9C=88=E5=BB=BA=E8=AE=AE?=
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit


<p>You have received the following email from test name (william.hqs@gmail.com):</p>
<p>This is test email!</p>

  Rendered home/send_mail.html.erb within layouts/application (0.1ms)
  Rendered layouts/_nav.html.erb (0.1ms)
  Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 4117ms (Views: 18.2ms | ActiveRecord: 0.0ms)

上面 console 的 log 应该是发送成功了 但是 Gmail 账户里没有接收到邮件!

development.rb

onfig.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :domain               => 'localhost:3000',
    :user_name            => 'huqius',
    :password             => 'huqiuspassword',
    :authentication       => 'plain',
    :enable_starttls_auto => true  }
  #config.action_mailer.delivery_method = :sendmail
  # Defaults to:
  # config.action_mailer.sendmail_settings = {
  #   :location => '/usr/sbin/sendmail',
  #   :arguments => '-i -t'
  # }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

Mailer.rb

class Mailer < ActionMailer::Base
  #default from: "from@example.com"
  default from:"huqius@gmail.com"
  def contact_email(name,email,body)
    @name = name
    @email = email
    @body = body
    mail to: "william.hqs@gmail.com", subject: '测试邮件'
    #mail :to => user, :from => "william.hqs@gmail.com", :subject => "关心用户"
  end
end

共收到 6 条回复

:user_name => 'huqius@gmail.com'

Mailer.contact_email(...).deliver

#1 楼 @dddd1919 就是用的这个。

#2 楼 @bydmm

Mailer.contact_email(name, email, body).deliver

已经发送了!

#3 楼 @autumnwolf :user_name should be the entire email address look here

#5 楼 @dddd1919 嗯 我加了@gmail.com 不过没有重启服务器!重启服务器之后好用了

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册