Actionmailer not working when I change gmail password - ruby-on-rails

I have a Rails app that uses Gmail to send Actionmailer emails. It has been working great for months, but now that I changed my Gmail password it has stopped working and I get an error:
Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted.
I've adjusted the new password in my production.rb and development.rb files:
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
#domain: 'thetens.us',
user_name: 'myaddress#gmail.com',
password: 'mypassword',
authentication: 'plain',
enable_starttls_auto: true }
I'm sure the password is correct. Is there some way to force it to update wherever it's not being updated?

Create a file named as setup_mail.rb in config/initializers/ folder so that it looks like
config/initializers/setup_mail.rb
and put the below code in that file:-
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'www.yourdomain.com',
:user_name => "myaddress#gmail.com",
:password => "mypassword",
:authentication => 'plain',
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "www.yourdomain.com"

Related

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
}

Rails actionmailer, gmail works, office 365 does not.

I've got Actionmailer sending emails using gmail with the following settings:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "user_name#gmail.com",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
However, I can't get office 365 mail to work, I have the following settings:
ActionMailer::Base.smtp_settings = {
:address => "smtp.office365.com",
:port => 587,
:domain => "my_domain.com",
:user_name => "username#my_domain.onmicrosoft.com",
:password => "password",
:authentication => :login,
:enable_starttls_auto => true
}
If I try and send an email with this client I get:
Net::SMTPFatalError
550 5.7.1 Client does not have permissions to send as this sender
Turns out microsoft requires the same email for both the smtp_settings and the :from field in emailer.rb.
I have faced same issue with Gmail and Office365, after scratching head for many hours I find out solution.
If you are using Office365 account for sending emails, it only works if user_name and sender_address and same value. i.e
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.office365.com',
port: 587,
domain: 'my_domain.pk',
user_name: 'noreply#my_domain.pk',
password: ENV['PASSWORD'],
authentication: 'login',
enable_starttls_auto: true
}
config.middleware.use ExceptionNotification::Rack,
email: {
deliver_with: :deliver,
email_prefix: '[Email Prefix]',
sender_address: %{<noreply#my_domain.pk>},
exception_recipients: %w{abc#gmail.com}
}
config.action_mailer.perform_deliveries = true
Key Point: So keeping following values same worked for me
user_name: 'noreply#my_domain.pk'
sender_address: %{<noreply#my_domain.pk>}
Read more on sending with SMTP through Office 365 over here:
https://technet.microsoft.com/en-us/library/dn554323.aspx
With the authentication method like this you don't need to set :domain.
In devise.rb I set "no-reply#******.com", and I mentioned at production.rb in smtp setting as "noreply#*****.com".
After replace the email id in devise.rb as "no-reply#*******.com" with "noreply#******.com", it's working fine now.

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

How to send confirmation e-mails using gmail smtp service for registration using devise under development mode locally?

I have an app , it uses devise to send confirmation mails for the newly registered users , I have smtp settings under the development.rb file as
config.action_mailer.default_url_options = { :host => 'http://localhost:3000' }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:user_name => "my_username#gmail.com",
:password => "mygmail password"
}
This is throwing me with an error like ,
Net::SMTPAuthenticationError in Devise::RegistrationsController#create
535-5.7.1 Please log in with your web browser and then try again. Learn more at
Any Ideas how to resolve this ?
Resolved using these settings ..
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "my_username#gmail.com",
:password => 'my_gmail password',
:authentication => "plain",
:enable_starttls_auto => true
}
I was unuable to resolve this problem with any code. After a while i logged in to gmail account and this is, what it gave me after.
We've detected suspicious activity on your Google Account. Please create a new password to continue using your account.
Read some tips on creating a secure password.
So solution to this problem is simply log into account you use for email sending and reconfirm your new password
:authentication => 'plain'
# ActionMailer Config
config.action_mailer.default_url_options = {:host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# change to false to prevent email from being sent during development
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: "example.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "your_mail#gmail.com",
password: "your_password"
}
After making your development.rb file like this, then if you have problem means please login to your gmail account, which is used in the development.rb file.
Then problem will be solved.

ActionMailer not working on localhost with gmail or google apps for Rails 3.1.3

I'm using sendgrid on heroku to send email in production, but would like to send email locally on my mac.
I've configured my development.rb a million different ways and keep getting
"Net::SMTPFatalError: 550 Cannot receive from specified address : Unauthenticated senders not allowed"
Spefically, I tried
varying authentication b/w :plain and :login,
tried using my gmail account credentials,
tried using my google app account credentials.
Nothing seems to work, thoughts?
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'somedomain.com',
:port => 587,
:user_name => 'username#somedomain.com',
:password => 'somepassword',
:authentication => :plain,
:enable_starttls_auto => true
}
I thought I had set the in the production settings (production.rb), it turns out I had set them in environment.rb. Removed it there and everything started working.
I had set the mail settings by accident in the Environment.rb so it was overriding anything I was doing at the production/development config level.
Could you try this?
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "email#gmail.com",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}

Resources