Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action::Mailer not delivering mail to the recepients

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

Do I need to add any gem to implement this?

development.log

Started GET "/contacts/3" for 127.0.0.1 at 2014-07-16 10:48:07 +0530 Processing 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: 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)
like image 782
Suganya Avatar asked Jul 15 '14 06:07

Suganya


1 Answers

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

I added these lines in development.rb file.

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

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.

like image 126
Suganya Avatar answered Sep 22 '22 06:09

Suganya