Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a rails app for booking cabs online. I want my app to have the functionality of sending emails to users once their booking is confirmed. For this, I am following Ryan Bates railscasts:

`https://www.youtube.com/watch?v=v1KI571TdUQ`

I started with creating a setup_mail.rb file in app/config/initializers, with the following content:

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

I then generated a mailer named user_mailer and included the following in app/mailers/user_mailer.rb:

class UserMailer < ActionMailer::Base
default :from => "no-reply@taxibol.in"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Registered")
end
end

and the following in app/views/user_mailer/registration_confirmation.text.erb:

Welcome to example.com!
===============================================

You have successfully signed up to taxibol.in.

Thanks for joining and have a great day!

Finally, in my static_pages_controller.rb, I included the following:

class StaticPagesController < ApplicationController
def booking_confirmation
UserMailer.registration_confirmation(current_user).deliver
end
end

I tested this in my localhost env, and it seems to have worked. Following is the relevant section in

Started GET "/booking/confirmation" for 127.0.0.1 at 2014-12-13 08:30:14 -0800
Processing by StaticPagesController#booking_confirmation as HTML
←[1m←[35mUser Load (2.5ms)←[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Rendered user_mailer/registration_confirmation.text.erb (0.0ms)

UserMailer#registration_confirmation: processed outbound mail in 10.0ms

Sent mail to rahul.pod@gmail.com (2037.5ms)
Date: Sat, 13 Dec 2014 08:30:14 -0800
From: no-reply@taxibol.in
To: rahul.pod@gmail.com
Message-ID: <548c6996cb448_32b42adff3848954@Rolu.mail>
Subject: Registered
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit

Welcome to example.com!
===============================================

You have successfully signed up to taxibol.in.

Thanks for joining and have a great day!

However, I checked my gmail account (rahul.pod@gmail.com), but I didn't receive any mail. What could be the reason?

**Update:**

Instead of creating the setup_mail.rb file, I tried to include the following in config/environments/development.rb:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = {host: 'localhost', port: 3000}

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: "587",
domain: "gmail.com"
authentication: "plain",
enable_starttls_auto: true,
user_name: "no_reply@taxibol.in"
password: "some_password"
}

Again got the same log trails, but no mail yet :(
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900