user3576036
user3576036

Reputation: 1425

actionmailer not sending emails even after setting all the possible configurations

This is the method inside ApplicationMailer

class CancelTrip < ApplicationMailer
    default from: '[email protected]'

    def cancel_trip
        @recvr= "[email protected]"
        mail(to: @recvr, subject: 'Your trip has been cancelled as per your request' )
    end
end

And the environmental variables as follows:

SMTP_ADDRESS: 'smtp.gmail.com'
SMTP_PORT: 587
SMTP_DOMAIN: 'localhost:3000'
SMTP_USERNAME: '[email protected]'
SMTP_PASSWORD: 'gggh2354'

And I am call the mailer method in my controller as follows:

def cancel
   xxxxx
   CancelTrip.cancel_trip.deliver_now
end

developement.rb has following

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

Log shows the email being sent. But I dont see any email in inbox. My rails version is 4.2.6.

Upvotes: 0

Views: 84

Answers (5)

Ajinath  Jedhe
Ajinath Jedhe

Reputation: 180

One possibility may be your firewall not allows to send email. Try connect different network.

Upvotes: 0

Ctpelnar1988
Ctpelnar1988

Reputation: 1255

Make sure that your ApplicationMailer is inheriting from ActionMailer::Base.

class ApplicationMailer < ActionMailer::Base
  default from: '[email protected]'
  layout 'mailer'
end

Upvotes: 0

Dima I. Belinski
Dima I. Belinski

Reputation: 381

use letter opener in development for be sure your actionmailer delivered your mail. after that you can finding deliver error to gmail or other.

Upvotes: 0

puneet18
puneet18

Reputation: 4427

Add following smtp setting on config/application.rb file:

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 587,
      :domain => "gmail.com",
      :user_name => "[email protected]",
      :password => "xxxxxxxx",
      :authentication => "plain",
      :enable_starttls_auto => true
  }

Upvotes: 1

Dave
Dave

Reputation: 323

Check in junk mail... I had this problem a little while back

Upvotes: 0

Related Questions