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
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With