0

I'm using ruby on rails to send some emails:

I wanted to test ActionMailer with my personal gmail account, from my console. however google is displaying the following errors:

Sign-in attempt was blocked

Someone just used your password to try to sign in to your account from a non-Google app. Google blocked them, but you should check what happened. Review your account activity to make sure no one else has access. Check

I used to be able to just use any of the answers from these questions:

Can't send email using Gmail on Heroku

Can't send mail with gmail stmp server (in discourse)

why is devise not sending email via gmail smtp?

But now I just can't send emails using my google account.

What changed? How do I configure my gmail to be able to do this?

This is the code I run from my console:

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.smtp_settings = {
  address:              'smtp.gmail.com', 
  port:                 587, 
  domain:               'gmail.com',
  authentication:       'plain', 
  enable_starttls_auto: true, 
  user_name:            'some@gmail.com',
  password:             '********'
}

mailer = ActionMailer::Base.new

# send mail:
mailer.mail(from: 'some@gmail.com', to: 'some_other@gmail.com', subject: 'test', body: "Hello, you've got mail!").deliver
Community
  • 1
  • 1
Alvaro Alday
  • 343
  • 3
  • 19
  • 2
    This is surely a google issue, having nothing to do with rails. Rails is ok. – Aleksei Matiushkin Jul 19 '19 at 07:09
  • @AlekseiMatiushkin Well, I already know that. The interesting bit is to find a fix or workaround for this. – Alvaro Alday Jul 19 '19 at 07:11
  • 1
    Have you had a look at something like this https://howilearnedrails.wordpress.com/2017/08/16/gmail-security-blocking-rails-emails/ ? Using a personal email address to perform mailing from a server is considered like a suspicious activity (and they're right) by Google. You need an app password to achieve this – cercxtrova Jul 19 '19 at 07:13
  • 1
    I quit any G accounts three years ago when they started to conquer the privacy of users, but I think enabling Less Secure App Access here https://myaccount.google.com/u/0/security?hl=en might help. – Aleksei Matiushkin Jul 19 '19 at 07:17
  • @AlvaroAlday Guess after making your google account less secure it takes some time to process it. Also follow this https://stackoverflow.com/questions/26941692/rails-4-actionmailer-with-gmail-netsmtpauthenticationerror-534-5-7-14/26941927 – Anand Jul 19 '19 at 07:22
  • BTW many mail services (AWS SES, Mailgun etc) have generous free tiers that will let you test sending hundreds of mails a month. GMail, especially a free acount, is more likely to reject programmatically generated emails and you also risk being locked out of your account. – mahemoff Jul 19 '19 at 09:00
  • I'll have in mind the fact that Google might lock me out, however, I just need it to test a little bit for the time being. – Alvaro Alday Jul 19 '19 at 17:57

1 Answers1

0

You can enable two factor authentication with your google account and write down the codes they give you (last time I checked they gave you about 10 of them), then use one of these codes to authenticate your Rails application when sending e-mail instead of your account password.

Nick M
  • 2,424
  • 5
  • 34
  • 57