sendgrid addon on heroku and devise - ruby-on-rails

Please help! I can't seem the get the sendgrid addon to work, and I have devise. Is there a way just to use a devise as a sender of e-mails, if so, then how? Or what am I doing wrong:
Here is my significant config/initializers/devise.rb code:
Devise.setup do |config|
# ==> Mailer Configuration
#config.mailer_sender = "myapp.herokuapp.com"
# Configure the class responsible to send e-mails.
#config.mailer = "Devise::Mailer"
Do I have to uncomment this if i want to use sendgrid?
In enviroment/production.rb I have:
config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com' }

Have you done the basic Sendgrid configuration?
https://devcenter.heroku.com/articles/sendgrid
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}

Related

Ruby on Rails and Sendinblue via SMTP

I would like to use Sendinblue to send transactional email from my Ruby on Rails web application via SMTP.
I edited config/environments/production.rb as follows:
ActionMailer::Base.smtp_settings = {
:address => 'smtp-relay.sendinblue.com',
:port => '587',
:authentication => :plain,
:user_name => ???,
:password => ???,
:domain => 'fireworks.com',
:enable_starttls_auto => true
}
What am I expected to use as user_name and password? My account's username and password or my SMTP keys? Also, am I required to use any gem, like sib-api-v3-sdk, or this gem is useful only for sending email using the Sendinblue API?
This is all you need to use SendInBlue with ActionMailer. Other answers suggest to use gems that are not required for SMTP. You DO NOT need the sendinblue or sib-api-v3-sdk gems to use SIB with ActionMailer in a plain vanilla Rails app.
#config/environments/production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => ENV.fetch('SMTP_HOST', 'smtp-relay.sendinblue.com'),
:port => ENV.fetch('SMTP_PORT', '587'),
:authentication => :plain,
:user_name => ENV['SMTP_USERNAME'], #See: https://account.sendinblue.com/advanced/api
:password => ENV['SMTP_PASSWORD'], #See: https://account.sendinblue.com/advanced/api
:enable_starttls_auto => true
}
Add this to your gemfile
gem 'sib-api-v3-sdk'
Add this to config/environments/production.rb
config.action_mailer.default_url_options = { host: "your_domain.com", port: 587 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp-relay.sendinblue.com",
:port => 587,
:user_name => ENV['SEND_IN_BLUE_USERNAME'],
:password => ENV['SEND_IN_BLUE_PASSWORD'],
:authentication => 'login',
:enable_starttls_auto => true
}
Add this in in config/initializers/send_in_blue.rb
SibApiV3Sdk.configure do |config|
config.api_key['api-key'] = ENV["SEND_IN_BLUE_API_KEY"]
end
Make sure your environment variables are correct. It works for me in production.
can add gem 'sendinblue'Official Sendinblue provided API V2 Ruby GEM
In order to send an email, you need to change the smtp settings in config/environments/*.rb(Whichever applicable)
Rails.application.configure do
#append this settings
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => ‘smtp-relay.sendinblue.com’,
:port => 587,
:user_name => ‘YOUR_SENDINBLUE_EMAIL’,
:password => ‘YOUR_SENDINBLUE_PASSWORD’,
:authentication => ‘login’,
:enable_starttls_auto => true
}
end
change STMP & API in Your setting account
STMP SERVER --> smtp-relay.sendinblue.com
port --> 587

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
}

Can we use smtp with heroku without the SendGrid add-on?

I am deploying an ruby-on-rails app in Heroku.I cannot add the SendGrid add-on to the heroku account.Is there any other ways to use the email services?
Yes you can simply sign up for a SendGrid account directly and then use the SMTP details. It would look like this:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587,
:domain => 'yourdomain.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => 'plain',
:enable_starttls_auto => true
}
There's also an example using the Mail gem, in the SendGrid documentation.
You could use your Gmail account.
In config > environment > production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => ENV['GMAIL_USER_NAME'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => 'plain',
:enable_starttls_auto => true
}
Then you have to set GMAIL_USER_NAME and GMAIL_PASSWORD to Heroku configs
GMAIL_USER_NAME should be your email address of gmail domain eg. sample#gmail.com

Sending Devise Confirmation Mailer with Mandrill through My Rails App on Heroku

I've got a Ruby on Rails app hosted with Heroku.
I'm using Devise for User Authentication. Trying to get Mandrill to send the Devise confirmation email.
I'm getting the following error in my heroku logs
Sent mail to EXAMPLE#gmail.com (23.4ms)
2015-02-04T00:38:02.334898+00:00 app[web.1]: Completed 500 Internal Server Error in 335ms
Note: the email is not being received by EXAMPLE#gmail.com.
Here's the code for Mandrill in my config/environments/production.rb
config.action_mailer.default_url_options = { :host => "example.herokuapp.com" }
config.action_mailer.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:enable_starttls_auto => true,
:user_name => ENV['EXAMPLE#heroku.com'],
:password => ENV['EXAMPLE'],
:authentication => 'login',
:domain => 'example.herokuapp.com'
}
EXAMPLE in the code above is actually replaced by my account information.
What am I missing?
I ended up switching to SendGrid as a Heroku AddOn and it solved my problem.
Here's the code that ended up working for me in config/environments/production.rb:
config.action_mailer.default_url_options = { :host => "http://www.EXAMPLE.com" }
config.action_mailer.smtp_settings = {
:user_name => 'EXAMPLE',
:password => 'EXAMPLE',
:domain => 'EXAMPLE.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}

Heroku actionmailer how to

I am trying to create an email adress. I have added the sendgrid plugin to my app.
Here is my application.rb
module Konkurranceportalen
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# all .rb files in that directory are automatically loaded.
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.mydomain.com",
:port => 25,
:user_name => "mail#mydomain.com",
:password => "mypass",
:authentication => :login
}
end
end
You need to change your settings for Sendgrid:
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN']
To create an regular email like mail#yourdomain.com you need an Mail Exhange host.
When you have choicen your mail exhange host you can create emails like mail#yourdomain.com
Now you need to setup the Mx record on you DNS server
And vola you have a email like mail#yourdomain.com
that doesn't look like the code you need to use SendGrid with on Heroku - the docs have all the details you need, here

Resources