I am trying to set up an email contact form on my Rails app, but I am having trouble figuring out how to get the settings in config/production to read my password, without comprising my account.
Here are a heroku configs:
Jillians-MacBook-Pro-2:noises3 Jillian$ heroku config
=== noises Config Vars
DATABASE_URL: xxxdatabaseurlxxx
LANG: en_US.UTF-8
RACK_ENV: production
RAILS_ENV: production
RAILS_SERVE_STATIC_FILES: enabled
S3_BUCKET: muzack
SECRET_KEY_BASE: xxxsecretxxx
gmail_password: xxxmy_passwordxxx
gmail_username: xxxmy_emailxxx
And my smtp settings, in config/production.rb:
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: ENV['gmail_username'],
password: ENV['gmail_password'],
authentication: :plain
}
And in config/initializers/smtp_settings.rb:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "jho3292#gmail.com",
:password => WHAT DO I DO HERE???
:authentication => :plain,
:enable_starttls_auto => true
}
Does anyone know how to do this correctly?
Related
This is my outgoing_mail.yml files
If click on the forgot password link It is showing in the delayed_job.log
My email is deliver got stuck please help me.
production:
address: "smtp.gmail.com"
port: "587"
user_name: "xxxxxx#gmail.com"
password: "password"
authentication: "plain" # plain, login, or cram_md5
domain: "domain_name.com"
outgoing_address: "xxxxxx#gmail.com"
default_name: "Instructure Canvas"
My SMTP settings are right but the in site admin settings there is feature option section there is an option "Use remote service for notifications" is No so is if you use remote service like mailer etc. this option turns into off.
And It's working fine.
In config/environments/production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host:'your host', port: 'xxx' }
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 => 'abc.com',
:user_name => "xxxx#mail.com",
:password => "xxxx",
:authentication => :plain,
:enable_starttls_auto => true
}
I am having a strange problem, I am coding a GMAIL contact form - which will use an existing Gmail username and password to send emails to a pre-specified Gmail account.
The issue I am having is that when I run everything locally it works just fine. Once I deploy to Heroku on the other hand ... I am not receiving the messages. When I run: heroku logs -t it seems to show that the message has been sent but nothing is still coming through.
Configuration:
ActionMailer::Base.default_url_options = { :host => 'domain.herokuapp.com' }
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:enable_starttls_auto => true,
:domain => 'domain.herokuapp.com',
:user_name => ENV['GMAIL_USERNAME'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => "login"
}
Note:
domain.herokuapp.com has just been subbed in for my actual domain.
Screen shot of server logs:
Does anyone have any idea of why this is not working or can point me to a resource to get this resolved?
I had a similar problem, it was connected to the configuration in config/enfironments/production.rb file i had
config.action_mailer.default_url_options = { host: 'http://barteringapps.herokuapp.com' }
I was able to solve this problem by changing the address. In development it should be http://127.0.0.1:3000, while it should be your domain in production.
Also your gmail domain is not correct, you should have gmail.com as domain
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: ENV["GMAIL_DOMAIN"],
authentication: "plain",
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"],
enable_starttls_auto: true
}
I followed this post, but be careful when configuring the default_url_options as it would give me problems with facebook omniauth
https://rubyonrailshelp.wordpress.com/2014/01/02/setting-up-mailer-using-devise-for-forgot-password/
our Rails 3.2 application's "resend activation code" mail feature was working until the code was transferred from the previous developer to us. Now we get this error
Net::SMTPAuthenticationError in UsersController#create
Our mail settings remain untouched like this:
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587,
:domain => "example.com",
:user_name => "username",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
We are somehow not able to figure it out as to why the email stop's working.
We have checked the gmail server also responding back to us via telnet.
We have also enabled the Less Secure Apps feature of Gmail's in Security -> Account permissions -> Access for less secure apps
Thanks in advance.
You mentioned using Gmail's settings, I'd say you should try this:
ActionMailer::Base.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: ENV['GMAIL_USERNAME'],
password: ENV['GMAIL_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true
}
If you're using Sendgrid, as above you should have something like:
ActionMailer::Base.smtp_settings = {
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
domain: 'heroku.com', #for your helo domain
address: 'smtp.sendgrid.net',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}
Don't forget to define your ENV variables appropriately.
You can find more discussion around this here
I have ActionMailer working correctly in both production and development. I use different smtp settings for each environment, gmail for development and a SendGrid account through Heroku for production. I manually switch the settings in the setup_mail.rb file to work in development and then switch them back before pushing into production. This prevents my gmail password from becoming public on github as the SendGrid/Heroku settings do not require my password in the file:
development setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mysite.com",
:user_name => "me#mysite.com",
:password => 'mypassword',
:authentication => "plain",
:enable_starttls_auto => true
}
production setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com'
}
ActionMailer::Base.delivery_method = :smtp
I am concerned that I will accidentally push the development settings with my password to github. I'd like to stop switching settings manually to prevent this from happening. How do I setup different ActionMailer Base smtp settings for development and production? Thanks
Have this setting in production.rb and development.rb, instead of having your password hard coded, you could use environment variables locally too, create a .env file in your project, which will be loaded when you cd in:
EMAIL=me#mysite.com
EMAIL_PASSWORD= mypassword
Use ENV['EMAIL'] AND ENV['EMAIL_PASSWORD'] in development.rb
trying to send email form Ruby on Rails but getting this:
SocketError in UsersController#create
getaddrinfo: nodename nor servname provided, or not known
My environments/development.rb file has:
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "my_company.org",
authentication: "plain",
enable_starttls_auto: true,
user_name: "my_username#my_company.org",
password: "my_pass"
}
and
config.action_mailer.delivery_method = :smtp
and
config.action_mailer.default_url_options = { :host => 'localhost:5000' }
# 5000 rather than 3000 as I am using foreman.
I did the same using my Gmail, following are my configurations, try and see it if works
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:user_name => "<my gmail>#gmail.com",
:password => "<my gmail password>",
:openssl_verify_mode => 'none'
}
and please note the
:openssl_verify_mode => 'none'
section to skip the SSL errors.
But sorry, I have no idea what the error is, probably you try to use the Gmail SMTP server with another domain name.
In case others face the same issue, I just wanted to add that I had the exact same problem trying to implement a mailing system with gmail in my Rails API, and adding :openssl_verify_mode => 'none' did not solve the problem for me.
Instead, installing the figaro gem and then adding my environment variable in application.yml like so:
gmail_username: "myemail#gmail.com"
gmail_password: "mypassword"
did the trick for me.
(and dont forget to change you SMTP settings: )
user_name: ENV['gmail_username'],
password: ENV['gmail_password'],