Ruby on Rails and Sendinblue via SMTP - ruby-on-rails

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

Related

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
}

¨504 5.7.4 Unrecognized authentication type¨ Rails app to MS Exchange

My question is very similar to this one but the accepted answer has not solved my problem.
Here is what I have for my config file:
# Config for mailserver
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :smtp
# SMTP settings for Exchange server
config.action_mailer.smtp_settings = {
:address => 'outlook.<domain>',
:port => 25,
:authentication => :ntlm,
:user_name => '<userName>#<domain>',
:password => '<unencryptedPassword',
:domain => '<domain>',
:enable_starttls_auto => true
}
I have tried setting up a relay connector on the Exchange server to accept requests from the IP address of my application.
Also, my original problem was before I used NTLM and my config file looked like so but I got the same error:
# Config for mailserver
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :smtp
# SMTP settings for Exchange server
config.action_mailer.smtp_settings = {
:address => 'outlook.<domain>',
:port => 25,
:authentication => :login,
:user_name => '<userName>#<domain>',
:password => '<unencryptedPassword',
:domain => '<domain>',
:enable_starttls_auto => true
}
I have successfully been able to send email using Gmail's SMTP server so I don't think it's the Rails side, but the Exchange server not recognizing my application.
Turns out I was using the wrong authentication because the Exchange server doesn't require any sort of authentication (mainly so printers, faxes, etc. don't need to authenticate).
Here's the resulting settings I used:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'outlook.<domain>',
:port => 25,
: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

Error when sending mails with Mandrill in Rails app

I'm having problems with an error when trying to send mails with my App with Mandrill.
I've seen a lot of people have this problem, and I'm sure it has to do with my mailer configuration. See if someone knows how to deal with this, because I'm desperate about it.
ERROR:
Errno::ECONNREFUSED (Connection refused - connect(2)):
production.rb
# Config default action mailer
config.action_mailer.default_url_options = { :host => "localhost" }
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:enable_starttls_auto => true,
:user_name => ENV["MANDRILL_USERNAME"],
:password => ENV["MANDRILL_PASSWORD"],
:authentication => 'login',
:domain => 'heroku.com'
}
# Setup for production - deliveries, no errors raised
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
We use Mandrill in production like this:
#config/environments/production.rb
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => "587",
:authentication => :plain,
:user_name => "username",
:password => "API key",
:enable_starttls_auto => true
}
We literally have no other options for Heroku - I think you should remove the default_url_options and domain options

ActionMailer not working on localhost with gmail or google apps for Rails 3.1.3

I'm using sendgrid on heroku to send email in production, but would like to send email locally on my mac.
I've configured my development.rb a million different ways and keep getting
"Net::SMTPFatalError: 550 Cannot receive from specified address : Unauthenticated senders not allowed"
Spefically, I tried
varying authentication b/w :plain and :login,
tried using my gmail account credentials,
tried using my google app account credentials.
Nothing seems to work, thoughts?
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'somedomain.com',
:port => 587,
:user_name => 'username#somedomain.com',
:password => 'somepassword',
:authentication => :plain,
:enable_starttls_auto => true
}
I thought I had set the in the production settings (production.rb), it turns out I had set them in environment.rb. Removed it there and everything started working.
I had set the mail settings by accident in the Environment.rb so it was overriding anything I was doing at the production/development config level.
Could you try this?
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "email#gmail.com",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}

Resources