i am trying to set up confirmable with heroku devise for my app. here is my code: (followed a few tutorials)
config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com' }
Rails.application.routes.default_url_options[:host] = 'myapp.herokuapp.com'
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
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: ENV["GMAIL_DOMAIN"],
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
i've added the heroku variables for the password/domain/username. but when i try to sign-up on my live site, i get an error.
does anybody see any errors? or can someone point me on how I can debug this? thanks!
Heroku & Gmail have some authentication token problem while sending e-mail.
It is better to use sendgrid or Mandrill by MailChimp
They both are free & configuration is very easy
Related
I'be been having some massive issues getting emails to send. I've tried multiple ways of doing things; using gmail, mailgun, sendgrid, the mailgun gem etc, no luck at all. For some reason it's trying to send using port 25 although, as you can see below, I'm specifying port 587. The error I get is:
Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):
My development.rb file is as follows:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => 'smtp.mailgun.org',
:port => 587,
:api_key => 'key-5d321b99f722e71f759993ee41512b99',
:user_name => 'postmaster#sandbox3ed8de9510c845c68bf0d867a8f25394.mailgun.org',
:password => '(mailgun password)',
:domain => 'sandbox3ed8de9510c845c68bf0d867a8f25394.mailgun.org',
:authentication => :plain,
:enable_starttls_auto => true
}
I have looked around for solutions however none seem to solve the issue. I'm totally out of ideas.
entire Development.rb document:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = false
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "chris.edhogben#gmail.com",
password: "<password>",
authentication: 'plain',
enable_starttls_auto: true
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
Try This configuration
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'localhost',
port: 25,
domain: 'exmaple.com',
enable_starttls_auto: false
}
Use the below settigns in production.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.mailgun.org',
:port => 587,
:user_name => 'postmaster#sandbox3ed8de9510c845c68bf0d867a8f25394.mailgun.org',
:password => '(mailgun password)',
:domain => 'sandbox3ed8de9510c845c68bf0d867a8f25394.mailgun.org',
:authentication => :plain
}
Use the below settigns for gmail:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "username",
password: "password",
authentication: 'plain',
enable_starttls_auto: true
}
If you get SMTP authentication error , then click on http://www.google.com/accounts/DisplayUnlockCaptcha & enable it. It will enable google for registering new apps within 10 minutes
add same mail configuration in production.rb also.
Restart the server and check
With the same config/application.rb (see below), I can send with one Gmail account, but not for a second Gmail account. The second Gmail account is preferred, I verified the login credentials with a browser and have ensured it accepts "less secure apps".
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: 'accountname',
password: 'secret',
authentication: 'plain',
enable_starttls_auto: true
Also with the second Gmail, I got NET::SMTPAUthenticationError in production, and it just does not send in development mode without complaining.
Finally, I am using Rails console, and my objective is to use a rake task to send email instead of in the web environment.
I am working on my first rails application and I have just pushed it to production through Heroku. The next step in my assignment is to create an account in production and have it send an email confirmation to that email.
config/environments/production.rb
config.action_mailer.default_url_options = { host: 'alex-bloccit.herokuapp.com' }
config/initializers/setup_mail.rb
if Rails.env.development?
ActionMailer::Base.delivery_method = :smtp
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
}
end
config/initializers/setup_mail.rb
if Rails.env.development? || Rails.env.production?
config/initializers/devise.rb
config.mailer_sender = "alex.colbert1987#gmail.com"
The code updates to github and pushes to Heroku just fine, but when I go to the website and I attempt to create an email under the email. Hope this provides enough information to troubleshoot.
In config/initializers/setup_mail.rb, you have if Rails.env.development? before the ActionMailer configuration. This config won't be run in production because of the way the if statement is structured.
I am getting this error whilst trying to send emails through gmail -
Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first. pw17sm4922458lab.5
):
app/controllers/contact_controller.rb:11:in `create'
I have tried loads of different things but to no avail, below is my settings from production.rb
# Change mail delvery to either :smtp, :sendmail, :file, :test
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "bizmodev.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: '******.*****#gmail.com',
password: '********'
}
# Specify what domain to use for mailer URLs
config.action_mailer.default_url_options = {host: "bizmo.co.uk"}
Any help on this matter would really be appreciated.
OK fixed it, basically I installed sendmail on my VPS and then restarted Apache and it now works -
Ubuntu Sendmail command line install
apt-get install sendmail
Hope this may help someone in the future...
you can enable starttls like this:
config.action_mailer.smtp_settings = {
....
:enable_starttls_auto => true}
I'm getting an error when sending out mail from the Production environment, specifically:
Net::SMTPAuthenticationError (530-5.5.1 Authentication Required)
On my local machine and development environment I'm declaring the passwords using ENV[GMAIL_USERNAME] and ENV[GMAIL_PASSWORD] and it's working fine, where the declared ENV is stored in my .bash_profile
# Development Environment for Action Mailer config
config.action_mailer.default_url_options = { host: '0.0.0.0:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.default charset: 'utf-8'
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'mydomain.com',
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
# Production Environment for Action Mailer config
config.action_mailer.default_url_options = { host: 'mydomain.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default charset: 'utf-8'
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "mydomain.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
Unfortunately, in Production I get an error when sending mail. However, if I hardcode the username and password in environments/production.rb it works. The ENV["GMAIL_USERNAME"] and `ENV["GMAIL_PASSWORD"] is set in the .bash_profile:
export GMAIL_USERNAME="hello#mydomain.com"
export GMAIL_PASSWORD="mypassword"
I thought it would it was the app unable to call ENV["GMAIL_USERNAME"] and ENV["GMAIL_PASSWORD"] but when I jump into the production rails console and puts ENV["GMAIL_USERNAME"] it outputs the correct credentials.
I have restarted Apache and restarted my app multiple times but I'm puzzled what to do next.
Any help is much appreciated.
Thank you in advanced.
Whose bash profile? Your users? Apache won't read those profiles on startup as it doesn't run bash to start the server.. Your profile gets sourced when you login to the server. Which is why it works when you test.
You need to make sure that environment variables are defined in the script or the environment that apache runs under. Depending upon your server this could be in /etc/apache2/envvars or added to the startup script for apache.