Question

I want to send email in my Rails app but I don't know why the email not sending to email destination, whereas in my log the email sending. Here's my email sender setting in environment/development.rb:

MyApp::Application.configure do

  config.cache_classes = false
  config.eager_load = false

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = false    
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load

  config.assets.debug = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :domain               => 'gmail.com',
    :user_name            => 'my_username',
    :password             => 'my_pass',
    :authentication       => 'plain',
    :enable_starttls_auto => true  }
end

Here's my UserMailer.rb:

class UserMailer < ActionMailer::Base  
    def checkout(admin_email, email, ids, store_name)
        @email = email
        @seller = admin_email
        @store_name = store_name
        @orders = []
        @store = Store.where("name = ?", store_name).first

        ids.each do |f|
          @orders << Order.find(f) 
        end   
        mail(:to => "<#{email}>", :from => "<#{admin_email}>", :subject => "checkout confirmation")
      end
end

and here's code in my controller for sending the email:

UserMailer.checkout(admin_email, email, ids, store.name).deliver

Why is this email seems to be sent, (according to logs) but not sent to recipient?

Was it helpful?

Solution

If you're using gmail, make sure your username field is actually: username@gmail.com i had a similar problem and it worked once i changed the username

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top