简体   繁体   中英

Rails 4 actionmailer not sending emails

I've tried everything I can think of to get emails to send with Rails 4.1.6 (local development) but nothing is working. Using Postmark I have the following in my development.rb and application.rb:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_key => API_KEY }
config.action_mailer.perform_deliveries = true

and for GMAIL I tried:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              'smtp.gmail.com',
  port:                 587,
  domain:               'gmail.com',
  user_name:            'my_email',
  password:             'my_password',
  authentication:       'plain',
  enable_starttls_auto: true  }

My Mailer class looks like so:

class BusinessMailer < ActionMailer::Base
  default from: "my_email@email.com"

  def claim_business business

    mail(
      :subject => 'hello',
      :to      => 'myemail@email.com',
      :from    => 'myemail@email.com',
      :html_body => '<strong>Hello John Doe<strong>',
      :track_opens => 'true'
    )

  end
end

And lastly I'm sending the email via: BusinessMailer.claim_business @business

When I trigger the claim_business method I see BusinessMailer#claim_business: processed outbound mail in 14.1ms in my console with no error messages. Can anyone tell me what I'm missing here?

You're missing deliver method to eventually send the email. Try:

BusinessMailer.claim_business(@business).deliver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM