2

As of may 30th, smtp is no longer accepted.

https://support.google.com/accounts/answer/6010255?hl=en&ref_topic=7188673

What is the new way to make a simple python emailer rather than a full application with the "login with google" option?

Not sure why I was asked for the code and error, given that I already diagnosed the issue and was asking for alternative methods. Here it is. Its a handy emailer that texts me to workout when I work at home.

import time
import smtplib
import random
gmail_user = '[email protected]'
gmail_password = 'TheCorrectPassword'

sent_from = gmail_user
to = ['[email protected]']
exercises = ['push ups', 'jumps in place', '20lb curls', 'tricep extensions', 'quarter mile runs']
levels = [1, 2, 3]
level1 = ['10', '15', '16', '20', '1']
level2 = ['15', '30', '30', '40', '2']
level3 = ['20', '50', '48', '70', '4']
while True:
    if int(time.strftime('%H')) > 9:
        if int(time.strftime('%H')) < 23:
            abc = random.uniform(0, 1)
            picker = random.randint(0, 4)
            if abc < 0.3:
                level = level1
            if 0.3 < abc and abc < 0.8:
                level = level2
            if abc > 0.8:
                level = level3
            exersize = exercises[picker]
            amount = level[picker]
            try:
                subject = f'Test'
                body = f'Do {amount} {exersize}'
                server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
                server.ehlo()
                server.login(gmail_user, gmail_password)
                server.sendmail(sent_from, to, body)
                server.close()
                print('Email sent!')
            except Exception as error:
                print(error)
            time.sleep(random.randint(1500, 4800))
    time.sleep(100)

error:

(535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials jj1-20020a170903048100b00163247b64bfsm7655137plb.115 - gsmtp')

Solved below: SMTP is still accepted for app passwords. App passwords creation steps can be found here, but you must enable 2 factor auth first, before app passwords can be created.

https://support.google.com/accounts/answer/185833 https://myaccount.google.com/security

5
  • Please edit your question and include your code. I would like to see how you are trying to do this currently. Also please include any error messages Commented Jun 14, 2022 at 20:40
  • @DaImTo done althought I dont feel anything important was added. The error points u to the doc I linked originally. I believe a lower answer about app passwords may be suffiecient, but appears that app passwords may not be possible unless you enable 2fa Commented Jun 14, 2022 at 20:46
  • Including your code in your question is a good practice. It allows me to copy your code and show you exactly how to fix it using the apps password. Apps password works fine with 2fa i have it enabled on my account and i have been testing with it all day. No problems. Commented Jun 14, 2022 at 20:54
  • that may be true, but I think i need to make a new dedicated email account as Id rather not have 2fa on this and slow down logins elsewhere Commented Jun 14, 2022 at 20:59
  • Security does slow things down. TBH never use your standard account for authorization. Commented Jun 15, 2022 at 6:17

2 Answers 2

2

Correction after May 30 2022, sending the users actual password is no longer accepted by googles smtp server

You should configuring an apps password this works. Then replace the password in your code with this new apps password.

An App Password is a 16-digit passcode that gives a less secure app or device permission to access your Google Account. App Passwords can only be used with accounts that have 2-Step Verification turned on.

gmail_user = '[email protected]'
gmail_password = 'AppsPassword'

This is normally due to the user having 2fa enabled.

Another option would be to use Xoauth2.

Sign up to request clarification or add additional context in comments.

2 Comments

Noting in the main post, this only works if you have an app password. And app passwords can only be created AFTER you enable 2 FACTOR AUTHENTICATION
its at the top of the page I linked on how to create one.
-1
import smtplib

host = "server.smtp.com"
server = smtplib.SMTP(host)
FROM = "[email protected]"
TO = "[email protected]"
MSG = "Subject: Test email python\n\nBody of your message!"
server.sendmail(FROM, TO, MSG)

server.quit()
print ("Email Send")

1 Comment

I can make this from my mac, but in my oldish debian this error remains. I wonder if this is related to openssl or some other cryptography in debian?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.