简体   繁体   中英

SendGrid not sending emails Heroku

I am trying to send mails with SendGrid from my Rails app (using Hartl's tutorial). It didn't work by simply using the addon at Heroku because it needed my credit card. Then I signed up on SendGrid and used my credentials as above, but still no mail. Here above is my production.rb file. Some help, please?

  config.action_mailer.delivery_method = :smtp
  host = '<https://nameless-sierra-13544>.herokuapp.com'
  config.action_mailer.default_url_options = { host: host }
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['myusername'],
    :password       => ENV['mypass#'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }

Merci,

In line with the comment above, I believe your values are just a little off. I also believe you need to have a from address set. This is a copy of what I use in production, with your values put in, and it works so hopefully this helps. I do believe that missing a valid from address and the characters in your domain value are why this is not working. Of course, also make sure you have the ENV variables set on heroku.

production.rb

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { host:'https://nameless-sierra-13544.herokuapp.com' }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"
  ActionMailer::Base.smtp_settings = {
    :from                 => 'your_email_here@email.com',
    :user_name            => ENV['myusername'],
    :password             => ENV['mypass#'],
    :domain               => 'https://nameless-sierra-13544.herokuapp.com',
    :address              => 'smtp.sendgrid.net',
    :port                 => 587,
    :authentication       => :plain,
    :enable_starttls_auto => true
  }

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