本文介绍了行动::邮件程序未将邮件传递给收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to send mail to the user when his profile is being viewed. i.e When a user clicks on show of a particular contact that contact will be notified about the profile view. I did not get any errors. But there is some delay where i have triggered the mailer. And also it works fine in the console. But the mail is not being sent to the recepient.

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

This is what I have tried so far.

mailer.rb

class CustomerSupport < ActionMailer::Base
    def customer_support(contact)
     mail :to => contact.email, :from => "[email protected]", :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来实现此目的?

Do I need to add any gem to implement this?

development.log

为127.0开始获取 / contacts / 3 .0.1在2014-07-16 10:48:07 +0530
由ContactsController#show处理为HTML
参数:{ id => 3}
[1m [36mContact加载(0.2ms)[0m [1mSELECT 联系人。*从联系人哪里联系人 id = 3 LIMIT 1 [0m
呈现的customer_support / customer_support.html.erb(0.1ms)

Started GET "/contacts/3" for 127.0.0.1 at 2014-07-16 10:48:07 +0530Processing by ContactsController#show as HTML Parameters: {"id"=>"3"} [1m[36mContact Load (0.2ms)[0m [1mSELECT contacts.* FROM contacts WHERE contacts.id = 3 LIMIT 1[0m Rendered customer_support/customer_support.html.erb (0.1ms)

CustomerSupport#customer_support:在11.9毫秒内处理了出站邮件

CustomerSupport#customer_support: processed outbound mail in 11.9ms

Sent mail to [email protected] (1797.4ms)
Date: Wed, 16 Jul 2014 10:48:07 +0530
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
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)


推荐答案

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

I tried to raise run time errors using the following code.

我将这些行添加到
development.rb 文件中。

I added these lines indevelopment.rb file.

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

我有犯了一个非常愚蠢的错误。我在Gmail帐户中启用了两步验证,该帐户用于默认的:from 。所以我禁用了它,然后我的应用程序开始工作了。

I have done a very silly mistake. I had two-step verification turned on in my gmail account which I used for default :from. So I disabled it and I got my application working.

这篇关于行动::邮件程序未将邮件传递给收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:07