Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mail not sent: sendgrid on heroku using Ruby on Rails

I'm attempting to send mail from ruby on rails app on heroku via sendgrid. This is a standalone app only trying to send an test e-mail. I get no errors but the 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: "[email protected]" 
    #sendgrid_category :use_subject_lines 
    #sengrid_enable :ganalytics, :opentrack

    def test_notification 
      mail(:to => "[email protected]", :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 prints out some log info..)

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

But send_grid doesn't report any mail sent out from my account. Not do I receive the e-mail.

I have also tried to send mail by an other means by calling test_notification from /home/index/controller which will be sent when visiting the home page of the app.

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

end

===

Stats don't report the mail as sent either. Any help is greatly appreciated.

Thanks! DS

like image 454
Srinivas Dangeti Avatar asked Nov 02 '11 05:11

Srinivas Dangeti


People also ask

How do I use SMTP in Ruby on Rails?

Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.

Can Heroku send email?

The Heroku Elements marketplace has a suite of email add-ons. Consult the Heroku Elements marketplace and attach an email add-on that matches your requirements.


1 Answers

try

Notifier.test_notification.deliver

you need to call the deliver method on your method to actually send the message.

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

like image 125
John Beynon Avatar answered Oct 22 '22 17:10

John Beynon