Actionmailer不向收件人发送邮件

时间:2014-07-15 06:46:04

标签: ruby-on-rails-4 actionmailer

我试图在查看个人资料时向用户发送邮件。即当用户点击特定联系人的节目时,该联系人将收到关于个人资料视图的通知。我没有得到任何错误。但是我触发了邮件有一些延迟。它也可以在控制台中正常工作。但邮件没有发送给收件人。

这是我到目前为止所尝试过的。

mailer.rb

class CustomerSupport < ActionMailer::Base
    def customer_support(contact) 
     mail :to => contact.email, :from => "sugukvs92@gmail.com", :subject => "profileviews"       
  end
  end

为setup_mail.rb

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
   :address => "smtp.gmail.com",
   :port => 587,
   :domain => "gmail.com",
   :user_name => "sugukvs92",
   :password => "**************",
   :authentication => "plain",
   :enable_starttls_auto => true
}

controller.rb

def show
  @contact = Contact.find(params[:id])
    CustomerSupport.customer_support(@contact).deliver

end

我是否需要添加任何gem来实现它?

development.log

在2014-07-16 10:48:07 +0530开始获取127.0.0.1的GET“/ contacts / 3” 通过ContactsController处理#显示为HTML   参数:{“id”=&gt;“3”}   [1m [36mContact Load(0.2ms)[0m [1mSELECT contacts。* FROM contacts WHERE contactsid = 3 LIMIT 1 [0m   呈现customer_support / customer_support.html.erb(0.1ms)

CustomerSupport #customer_support:11.9ms处理出站邮件

Sent mail to suganya.gnanasekar@in.reportbee.com (1797.4ms)
Date: Wed, 16 Jul 2014 10:48:07 +0530
From: sugukvs92@gmail.com
To: suganya.gnanasekar@in.reportbee.com
Message-ID: <53c60b0f7e609_b993ec57901998d@ameex.mail>
Subject: customer support from Report Bee
 Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Welcome to example.com, </h1>
<p>
  You have successfully signed up to example.com,

</p>
<p>
  To login to the site, just follow this link: 
</p>
<p>Thanks for joining and have a great day!</p>
 </body>
 </html>
 Rendered contacts/show.html.erb within layouts/application (0.6ms)
Completed 200 OK in 1829ms (Views: 16.2ms | ActiveRecord: 0.2ms)

1 个答案:

答案 0 :(得分:6)

我尝试使用以下代码引发运行时错误。

我添加了这些行 development.rb 文件。

config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

我犯了一个非常愚蠢的错误。我在我的gmail帐户中启用了两步验证,我将其用于默认:from。所以我禁用了它,我的应用程序正常运行。