Mail not sent: sendgrid on heroku using Ruby on Rails

I am trying to send mail from ruby โ€‹โ€‹to a rails application on heroku via sendgrid. This is a standalone application that tries to send a test email. I do not receive errors, but mail is not sent. Your help is appreciated.

== config/environment.rb === ActionMailer::Base.smtp_settings = { :user_name => ENV['SENDGRID_USERNAME'], :password => ENV['SENDGRID_PASSWORD'], :domain => ENV['SENDGRID_DOMAIN'], :address => "smtp.sendgrid.net", :port => 587, :authentication => :plain, } === ==== config/environments/production.rb === config.action_mailer.delivery_method = :smtp config.action_mailer.raise_delivery_errors = true ===== == app/models/notifier.rb == class Notifier < ActionMailer::Base include SendGrid default from: " abc@yahoo.com " #sendgrid_category :use_subject_lines #sengrid_enable :ganalytics, :opentrack def test_notification mail(:to => " xyz@gmail.com ", :subject => "mail from heroku") puts("Sent mail from notifier") end end ======== 

I tried running the test_notification method from heroku console

 >> Notifier.test_notification 

(This displays some log information ..)

 #<Mail:Message:279922420, Multipart: false, Headers: <from.., To, Subject, etc). 

But send_grid does not report any mail sent from my account. Do not receive email.

I also tried sending mail in another way by calling test_notification from / home / index / controller, which will be sent when I visit the applicationโ€™s home page.

 === class HomeController < ApplicationController def index Notifier.test_notification() end end === 

Statistics also do not report sent mail. Any help is appreciated.

Thanks! DS

+4
source share
2 answers

to try

 Notifier.test_notification.deliver 

you need to call the deliver method for your method to send the message.

http://guides.rubyonrails.org/action_mailer_basics.html

+6
source

Make sure you have the SendGrid add-on for your Heroku. To code

 user_name => ENV['SENDGRID_USERNAME'], :password => ENV['SENDGRID_PASSWORD'], :domain => ENV['SENDGRID_DOMAIN'], 

Details must be your username, password and sendgrid domain

0
source

Source: https://habr.com/ru/post/1379251/


All Articles