0

I am trying to send notification mail using Action mailer in rails 4 but it is not working properly. After solving many error I am able to send the mail and no error shows in the console but the mail is not received. This has always worked for me before but I dont know how it is not happening now. Here is my output in the console.

AdminMailer#subscription_added: processed outbound mail in 202.7ms Sent mail to [email protected] (9.8ms) Date: Sat, 28 Nov 2015 21:25:52 +0530 To: [email protected] Message-ID: <[email protected]> Subject: Subscription addded Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit <!--XRAY START 8 /home/yogesh/Desktop/new/munam/app/views/layouts/mailer.html.haml--> <hmtl> <body> <!--XRAY START 7 /home/yogesh/Desktop/new/munam/app/views/admin_mailer/subscription_added.html.haml--> name of receiver Email [email protected] <!--XRAY END 7--> </body> </hmtl> <!--XRAY END 8--> Completed 302 Found in 320ms (ActiveRecord: 70.3ms) 

Here is my code for it

In my development.rb

Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true # Adds additional error checking when serving assets at runtime. # Checks for improperly declared sprockets dependencies. # Raises helpful error messages. config.assets.raise_runtime_errors = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true config.action_mailer.default_url_options = { :host => "localhost:3000" } # Automatically inject JavaScript needed for LiveReload # config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload) config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'localhost:3000', user_name: '[email protected]', password: 'mypassword', authentication: 'plain', enable_starttls_auto: true } end 

My code that triggers the mail

AdminMailer.subscription_added(@subscription).deliver_now 

My Admin mailer

class AdminMailer < ApplicationMailer def subscription_added(subscription) @subscription = subscription begin mail(:to => "[email protected]", :subject => "Subscription addded") rescue Exception => e end end end 

I will really thankful if someone tells me where I am going wrong or what extra do I need to do. Thanks a lot in advance.

6
  • What is your code that trigger this email ? Commented Nov 28, 2015 at 16:15
  • @Rubyrider Updated the question Commented Nov 28, 2015 at 16:17
  • are you expecting to receive email? is this really sending emails to this address [email protected]" ? Could you try it with an real email address if you haven't checked already? Commented Nov 28, 2015 at 16:21
  • Ofcourse the code has real email address Commented Nov 28, 2015 at 16:22
  • after updating the mailer configuration on development.rb have you restarted your server also? Never mind in order to understand I have to ask these question gradually to sort your problem. Commented Nov 28, 2015 at 16:24

2 Answers 2

1

You're hiding any errors that may occur when trying to send the email, with this line:

config.action_mailer.raise_delivery_errors = false

Change it to true, restart your server, and you will get an error if you try to send mail and it fails.

In development, I'd recommend against using a real live mail server, though - I'd recommend using something like Mailcatcher (http://mailcatcher.me/)

Sign up to request clarification or add additional context in comments.

Comments

1

Try to raise run-time errors using the following code in development.rb file.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.