I am developing a website using ROR on Windows 7 (64-bit). I am trying to setup my website so that a person who creates a new login on it gets a confirmation email. I am using ActionMailer for the email confirmation sending. I am trying to configure it to send confirmation email using Gmail SMTP server. (This is just for testing. Once it works, I can use something else on the deployment server.)
I am getting this error:
Application-specific password required
Here is the code snippet from development.rb:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:authentication => :login,
:user_name => 'my_login#gmail.com',
:password => 'my_application_specific_password'
}
Why I am getting this error even though I generated a new application-specific password for this purpose and am using it? How to fix this?
I think you may have enabled extra 2-step security on the Google Account you are using to send emails. This can require you to sign in using a special code sent to your mobile phone by text message; or for particular non-compatible applications, creating an 'Application-specific password'.
More details on Application-specific passwords here.
Related
I am trying to set up the "forgot password" function that comes with devise. I am using rails 5. It always gives me the error: "535-5.7.8 Username and Password not accepted"(Net::SMTPAuthenticationError in Users::PasswordsController#create though.
My code looks like this:
In development.rb I added:
config.action_mailer.default_url_options = { host: 'localhost', port:3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:domain => 'gmail.com',
:user_name => 'xyz#gmail.com',
:password => 'abcde',
}
Under config > initialisers > devise.rb I added:
config.mailer_sender = "xyz#gmail.com"
and under config > environment.rb:
ActionMailer::Base.delivery_method = :smtp
Am I missing anything or did I do something wrong?
Also another question: I need to link it to my personal account (i.e. replace the user_name and password with the details of a real email account), there is no default devise account the emails get sent from, right? I'm just wondering because like this everyone in my team would be able to see the password of the mail account we're using, right?
Any advice would be highly appreciated! Thanks in advance.
SMTPAuthenticationError is an error at the SMTP authentication layer.
This means that whatever SMTP service you're trying to use is reporting back some kind of authentication issue.
I do not use Gmail as my SMP, but this error seems strange to me as it says Username and Password not accepted, which is different from incorrect.
Further research shows that Gmail no longer accepts less secure SMTP requests.
Google now doesn't accept login from less secure apps. So you need to go to https://myaccount.google.com/security scroll to the bottom and turn ON "Allow less secure apps: ON". Now when you add the SMTP details to "Send as" google will accept them. You need to do this for the email ID you are adding in your Send as section.
I think it's related with your gmail settings. If you see errors like Net::SMTPAuthenticationError while using gmail for sending out emails, visit your gmail settings and enable less secure apps:
"MyAccount" > "Sign-in & security" > "Connected apps & sites" > "Allow less secure apps"
Go to your google email account setting and change this settings. and try more than 1 times.
I am stuck with sending emails in Rails. I need to send password reset or activation account emails using Devise gem. Thanks Devise has email sending functionality builtin. I only need to configure sender. I have googled and found many tutorials on how to do that. Here are the things I still don't understand as many tutorials do not talk about them much:
Any tutorial comes with something like that:
config.action_mailer.default_url_options = { :host => 'gmail.com' }
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
# SMTP settings
ActionMailer::Base.smtp_settings = {
:port => 587,
:address => 'smtp.gmail.com',
:domain => 'gmail.com',
:user_name => ENV['username'],
:password => ENV['password'],
:authentication => :plain,
}
So unclear things for me are:
1) what is :host, can I use localhost?, in example it is gmail.com. Do I need to set up some gmail server or whatever.
2) what is :domain, again is it my site domain? or using just gmail.com is fine?
3) What is user_name and password?
So the general question is do I need to install some server for mail on my production server and so on, people on this tutorials skip this part. Who sends my email? Rails app server? or separate smtp server?
1) host is a variable used to generate links to your site in the email (see comment).
2) domain is the sending domain of the email, if you have your own domain you could put your domain there.
3) user name and password are the credentials of your gmail account (or the account that you send mails from). If you have your own smtp relay server set up you can use information for that.
This will likely only work for a minimal number of emails sent, you need to look into a professional service that delivers your emails if you intend on sending more than about 100 per month.
When ever time i try sending notifications in my rails app i get the following error
Net::SMTPAuthenticationError (535-5.7.1 Username and Password not accepted. Learn more at
):
app/models/friendship.rb:6:in `send_request'
app/controllers/friends_controller.rb:21:in `make_friendship'
my development.rb mail config settings is
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
# Gmail SMTP server setup
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:enable_starttls_auto => true,
:port => 587,
:domain => '#example.com',
:authentication => :plain,
:user_name => 'user#gmail.com',
:password => 'secret'
}
I have this and it works for me:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "name#example.com",
:password => 'password',
:authentication => "plain",
:enable_starttls_auto => true
}
Login to the account you're using in your browser then visit this page:
http://www.google.com/accounts/DisplayUnlockCaptcha
This gives you a 10 minute window to login with the app you want to let access your account. Go back to your Rails app and make it send an email, after that everything should work.
I have a similar configuration that works fine but once in a while I get this error and I suspect that it is because Google mark the account as potentially abusive for some reason, too fast logins etc (each time a mail is sent).
You can make it work again by manually login via web interface and type the CAPTCHA. If this happens often I would probably think about using some other solution, like using an own MTA or at least an local MTA between Rails and gmail capable of sending multiple mails without relogin. In that case you may even deliver the mail yourself without going thru gmail, just make sure to setup proper SPF records etc.
you are missing the link in the error message! :)
Net::SMTPAuthenticationError (535-5.7.1 Username and Password not accepted. Learn more at https://support.google.com/mail/bin/answer.py?hl=en&answer=14257
Thus for details see: https://support.google.com/mail/bin/answer.py?hl=en&answer=14257
Make sure that you've entered your full email address (e.g. username#gmail.com)
Make sure your mail client isn't set to check for new mail too often. If your mail client checks for new messages more than once every 10 minutes, your client might repeatedly request your username and password.
I had the same problem: it worked from my desktop (in development environment), but it failed from production environment (a server in Sweden...).
You have to login into your gmail account and check the emails if Google has prevented the sign-in attempt.
Im doing a ruby on rails project for work and they would like to use sendgrid, but they also like gmail. With gmail it allows you to send an email from the web browser under a different alias but now also supports sending that through another smtp server instead of their own.
I was wondering if then, it would be possible to send an email from the RoR project through to gmail (so management gets to keep their nice interface and sent box), but then it would forward it through to the sendgrid SMTP servers. Just to clarify I know how to and currently can send an email through gmail as a different alias, but this is specifically to forward it through to sendgrid after it gets to gmail.
I currently have a standard setup of:
Myapp::Application.configure do
config.action_mailer.default_url_options = { :host => 'www.mygenericwebsite.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:tls => true,
:authentication => :plain,
:domain => 'mygenericwebsite.com',
:user_name => "user#mygenericwebsite.com",
:password => "pA55w0RD"
}
class UserMailer < ActionMailer::Base
default :from => "HappyAdmin <user#mygenericwebsite.com>"
You could send via Sendgrid and BCC the Gmail address in your emails, and then apply a label to emails from the app based on the From address. Not sure if you can apply the Sent label, but another label would probably be all right. I think this would be simpler and more robust than sending each email twice.
Just wanted to point out that our product, PostageApp, will allow you to send via the Google SMTP if you are so inclined. All you have to do is add the SMTP details to your project and you're good to go.
I just checked with the personal project I have hooked up with Postage and all the emails sent out appear in the Sent Mail folder.
Let me know if that's what you're looking for, or if you have any other questions!
The emails now send from my local, but do not send from my box. I am returned this error. Anyone know what this might be?
Net::SMTPAuthenticationError (535 5.7.8 Error: authentication failed: authentication failure
):
My environments/production.rb
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => '25',
:domain => "mydomain.com",
:authentication => :plain,
:user_name => "email#gmail.com",
:password => "password1234"
}
/etc/ssmtp/ssmtp.conf :
root=postmaster
mailhub=smtp.sendgrid.net
AuthUser=email#gmail.com
AuthPass=password1234
AuthMethod=LOGIN
rewriteDomain=mydomain.com
FromLineOverride=YES
UseSTARTTLS=NO
This usually happens because your account hasn't been provisioned.
By the way, I find that it's more favourable to use PostFix with SendGrid so there is less delay for the user when they are using your rails app. When I was using SMTP (like you have above), I was getting long delays when loading an action that sent mail.
See this SendGrid wiki page for more info:
http://wiki.sendgrid.com/doku.php?id=postfix
When registering to SendGrid it will be moderated by admin before you can send mail from new account.
See:
https://support.sendgrid.com/hc/en-us/articles/200181628
I had a similar issue with my test server and due to inactivity, the account was disabled. I created a Support ticket with SendGrid and it was reactivated.