Setup SMTP settings for sending mail in rails - ruby-on-rails

I've followed the following tutorial to create a contact form.
Everything was fine, but as tutorial says For real e-mail delivery, you should set up SMTP in the environment settings. how can I set up SMTP?
As Suggested in this link I created and edited the smtp_settings.rb; But No luck at all. It still doesnot send the email to the real user.
smtp_settings.rb
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "myaccount#gmail.com",
password: "abcpassword",
domain: "mail.google.com",
authentication: :login,
enable_starttls_auto: true
}
end

It may be because your smtp_settings.rb file isn't being found by Rails, or that the delivery_method line isn't being recognised..
Try moving the file to /config/initializers/smtp_settings.rb if it isn't there already, and changing the contents slightly to
if Rails.env.production?
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "myaccount#gmail.com",
password: "abcpassword",
domain: "mail.google.com",
authentication: :login,
enable_starttls_auto: true
}
end
It could also be that the settings are only applied for production, if you're trying this out locally in development you'll need to remove the first line if Rails... and the last line end like so..
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "myaccount#gmail.com",
password: "abcpassword",
domain: "mail.google.com",
authentication: :login,
enable_starttls_auto: true
}
After any changes to this file you'll need to restart your rails server or rails console session for the changes to take effect.

Related

Rails not sending mails in development via Mandrillapp (nodename nor servname provided)

I'm running into this issue:
SocketError in Front::RequestsController#create
getaddrinfo: nodename nor servname provided, or not known
Extracted source (around line #539):
#537
#538 def tcp_socket(address, port)
*539 TCPSocket.open address, port
#540 end
#541
#542 def do_start(helo_domain, user, secret, authtype)
When trying to send mails via Mandrillapp locally. This is my development.rb file:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
# Specify what domain to use for mailer URLs
config.action_mailer.smtp_settings = {
user_name: 'my_user_name',
password: 'my_password',
domain: 'localhost:3000',
address: 'smtp.mandrillapp.com"',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}
On production everything works fine, even when loading those variables via Figaro (application.yml). However, on development mode, I'm running into the issue provided above.
I tried different ports, different settings... Nothing works on development. Could someone point me, at least, into the right debugging direction? Most SO-answers, like this doesn't help at all.
As per the details shared it seems there you have added an extra quote in address key when specifying smtp settings and when trying to connect to address it is showing this error:
Current Setting
config.action_mailer.smtp_settings = {
user_name: 'my_user_name',
password: 'my_password',
domain: 'localhost:3000',
address: 'smtp.mandrillapp.com"',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}
Update Setting:
config.action_mailer.smtp_settings = {
user_name: 'my_user_name',
password: 'my_password',
domain: 'localhost:3000',
address: 'smtp.mandrillapp.com',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}

Rails Gmail contact form - works on localhost but not when deployed to Heroku

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/

Ruby on Rails: How to Configure the Devise Mailer?

I have made an application on Ruby on Rails. I'm using Devise and I need to use the recoverable password feature.
I found these configurations on development.rb:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 2525,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "MY_EMAIL",
password: "MY_PASS"
}
When I test it, it looks okay, It doesn't throw any exception on the application, but the email never comes. Please, how can I configure this?
For using locally, I recommend using something like letter_opener.
For deploying the app I'd recommend using a service like Sendgrid, it has a free tier that is good enough for small apps.
If you insist on using GMail for e-mails, try using TLS:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
domain: "gmail.com",
port: 587,
user_name: "jorge#example.org",
password: "your_password",
authentication: 'plain',
enable_starttls_auto: true
}
Stumbled across this older question and figured I would provide a current answer here. If you're trying to use a Gmail account with your Devise Rails app for any reason (prototyping, developing, etc - no judgements), Pedro's answer is spot on with 1 exception. The password for the SMTP server is not your user password. This may have been ok in the past, but now you have to generate a new app password separate from your user password.
Directions can be found on Google's Support site here: https://support.google.com/accounts/answer/185833?hl=en

Ruby on Rails - SMTP authentication error

Hey guys I want to send an email when an user registers. so i have these settings:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: "587",
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "GMAIL_USERNAME",
password: "GMAIL_PASSWORD"
}
I have set the username and password variables and tried to have them like ENV["GMAIL_USERNAME"] and how you see in the code above and I always get the same error:
Net::SMTPAuthenticationError in UsersController#create
534-5.7.14 *and some link*
Are my settings wrong? I've even tried that google display unlock thing. But it still can't login

How to send emails in development environment using gmail SMTP and devise?

I am trying to send emails while being on localhost and using devise (I need emails for user registration and password reset)
I have put this in my environment.rb file
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["username"],
password: ENV["password"]
}
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
but I am not getting any mails and not seeing any error too (devise says ).
What am I missing ?
Where can I see the log for emails (success or
failure) ?
EDIT - OK, it worked after adding this line
:openssl_verify_mode => 'none'
Check this too rails email error - 530-5.5.1 Authentication Required.

Resources