I am following Ryan Bates's tutorial on Rails 3 ActionMailer. I generate the mailer in terminal and then establish a setup_mail.rb under config/initializers. I keyed in the following code:
ActionMailer::Base.smtp_settings={
:address => "smtp.gmail.com",
:port => 587,
:domail => "gmail.com",
:user_name => "my_account_at_gmail",
:password => "my_password",
:authentication => "plain" ,
:enable_starttls_auto => true
}
My user_mailer.rb file goes like:
class UserMailer < ActionMailer::Base
default :from => "my_account_at_gmail#gmail.com"
def registration_confirmation(user)
mail(:to => user.email,:subject => "registered")
end
end
I tested in rails console:
u=User.first
UserMailer.registration_confirmation(u).deliver
it displays:
#<Mail::Message:2194479560, Multipart: false, Headers: <Date: Sat, 26 Feb 2011 14:42:06 +0800>, <From: my_account_at_gmail#gmail.com>, <To: some_account#gmail.com>, <Message-ID: <some_number#My-MacBook-Pro.local.mail>>, <Subject: registered>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>
BUT I never received the email here... Why? How can I solve this? I guess it is some problem on send_mail.rb file..
If that's a copy/paste of your send_mail.rb, there is a spelling error in :domain (you have :domail) which may or may not be causing the issue.
If that doesn't work, try the following:
ActionMailer::Base.delivery_method = :smtp # be sure to choose SMTP delivery
ActionMailer::Base.smtp_settings = {
:tls => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :plain,
:user_name => "my_account_at_gmail#gmail.com", # use full email address here
:password => "password"
}
Alternatively, it has been been suggested in the Action Mailer Rails Edge Guide
to put the email configuration in the appropriate .rb file in your config/environments directory. For me, I put the following in config/environments/development.rb to get emails sent using gmail's SMTP server:
config.action_mailer.raise_delivery_errors = true #useful to have to debug
config.action_mailer.perform_deliveries = true #default value
config.action_mailer.delivery_method = :smtp #default value
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "yourdomain.com",
:user_name => "username#yourdomain.com",
:password => "yourpassword",
:authentication => :login, #or can use "plain"
:enable_starttls_auto => true
}
Related
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
Net::SMTPAuthenticationError in Devise::ConfirmationsController#create
530-5.5.1 Authentication Required. Learn more at
I am using the gem 'devise'.
to send confirmation email with gmail account.
but, the error in title occur.
I searched many cases similar to my case and tried solutions in there, but those perfectly not worked, so I think my error has some different origin
( what I tried is : 1. less securing myaccount.google.com/u/1/security 2. http://www.google.com/accounts/DisplayUnlockCaptcha)
development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => ENV["******#gmail.com"],
:password => ENV["******"],
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {:host => 'localhost:3000'}
top most error line in error page
def check_response(res)
unless res.success?
raise res.exception_class, res.message
end
end
please help me... TT
the problem your gmail setting, you should remove the ENV as you put string directly to it (as my understanding this is your local development this will generate an error since you also put config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => "******#gmail.com",
:password => "******",
:enable_starttls_auto => true
}
I'm trying to send an email to administrator from the production environment, but failing to... It works in development with letter opener gem, but when I try in production, I'm getting the following error:
Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at app/controllers/contact_us_controller.rb:8:in `submit_form'
app/models/contact_form.rb:13:in `send_admin_notification'
My code for the submit_form action in the controller is:
def submit_form
#contact_form.attributes = contact_form_params
return redirect_to action: :thanks if #contact_form.save
render :index
end
and the code in the contact_form model is:
def send_admin_notification
AdminNotifier.contact_form(self).deliver_now
end
I've been struggling with this for the past 2 days so any help and guidance would much much appreciated
This works well for me on the production env:
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'koshlendra#gmail.com',
:password => 'secret_password',
:authentication => 'login',
:enable_starttls_auto => true
}
Try putting these configurations in your production.rb file
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host:'yourhost'}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => "your email",
:password => "yourpassword",
:authentication => :plain,
:enable_starttls_auto => true
}
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
}
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