Mailer in Ruby on Rails - ruby-on-rails

I am migrating an ROR3 application to ROR4. And I am very new to this and I am learning along with the migration.
I got stuck in the first step it self
I am getting an error
Net::SMTPAuthenticationError in ClientsController#create
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbtq6
Here is my configuration in development.rb.
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => Rails.application.secrets.email_address,
:password => Rails.application.secrets.email_password,
:authentication => "plain",
:enable_starttls_auto => true }
The place where I am getting the error is at
#client.save.
Apartment::Tenant.create(#client.subdomain)
Apartment::Tenant.switch(#client.subdomain)
#client.save
redirect_to new_user_session_url(subdomain: #client.subdomain)
else
render action: 'new'
Can anyone help who is working on ROR?

I had this same issue, be sure to take a look at your gmail account security settings and enable "Access for less secure apps" from www.google.com/settings/security."

Try this
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "your mail",
:password => "your password",
:authentication => :plain,
:enable_starttls_auto => true
}

Related

resend confirmation mail error Net::SMTPAuthenticationError in Devise::ConfirmationsController#create

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
}

Rails, Gmail SMTP and failure

I am trying to set up an action mailer, so people can send a message using contact form on my website.
Here is my configuration for production:
config.action_mailer.default_url_options = { host: 'mydomain.co' }
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:authentication => :plain,
:user_name => ENV['GMAIL_USERNAME'],
:password => ENV['GMAIL_PASSWORD'],
:domain => 'mydomain.co',
:enable_starttls_auto => true
}
I was trying to test it and the mail is delivered, but after that I immidiately receive a message from "Mail Delivery Subsystem" with a subject "Delivery Status Notification (Failure)".
What is causing this message and how to avoid it?
Mine looks like this
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => ENV["GMAIL_USERNAME"],
:password => ENV["GMAIL_PASS"],
:authentication => 'plain',
:enable_starttls_auto => true
}
Also make sure you've enabled "Less Secure Apps" in your Gmail settings:
https://support.google.com/accounts/answer/6010255?hl=en
Hope that helps!

Admin notification email failure

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
}

Rails: Sending email after filling contact form

I'd like to create contact form using this tutorial
At the end of that is writen that I should configure SMTP, so in config/environments/developement.rb I set
config.action_mailer.default_url_options = {:host => 'myproject.c9.io'}
(I'm using rails on c9.io)
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "myusername",
:password => "mypassword",
:authentication => "plain",
:enable_starttls_auto => true
}
I'm fairly new in rails and especially in sending emails, so I'd like to ask, because I don't get message on my email address when I fill form and send, what should I do to get a confirmation of correct sending. I know that there is a lot of tutorials on the Internet but now I'm in the muddle, so I'll be grateful for explanation.
Add these config to your development.rb reference
config.action_mailer.default_url_options = {:host => 'myproject.c9.io'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'myusername',
password: 'mypassword',
authentication: 'plain',
enable_starttls_auto: true
}

Action mailer SMTP google apps

I tried to configure actionmailer to send via google apps with smtp.
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mydomain.com",
:user_name => "username",
:password => "password",
:authentication => 'plain',
:enable_starttls_auto => true }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
However whenever gitlab tries to send an e-mail:
Sent mail to user#my.domain.com (10ms)
Completed 500 Internal Server Error in 29ms
535-5.7.1 Username and Password not accepted
Server runs ruby 1.9.3p194. Why doesn't google apps accept the username/password?
It works now, I think the problem was with the username. it needs the domain in the username. i.e. the problem was
user_name: 'username'
Whereas the correct way (at least for google apps) is
user_name : 'username#mydomain.com'
this works for me:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "you#gmail.com",
:password => "password",
:authentication => 'plain',
:enable_starttls_auto => true }
Try setting the domain to gmail.com

Resources