Help with e-mail sender code

So i am following the “20 Beginner Projects” from freeCodeCamp, as such i tried to write the code first and only when i am stuck to use the help from the video.
Well i finished my email_sender-code (i checked it 4 times with the code from the video) yet i always get the error g.mail didin’t accept my “email_sender” and “email_password” variables and sadly the video couldn’t answer my issue.
I tried looking in the library but got confused in the end :cry: .
I purposefully left the “email_sender” and “email_password” empty, both contain letters and numbers, i firs thought that that is the issue, but shouldn’t the numbers still be written n correctly.
Repl link:

code snippet

Error message:
Traceback (most recent call last):
File “c:\Users\Azatg\OneDrive\Desktop\Phyton-Programme\”, line 34, in
smtp.login(email_sender, email_password)
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\”, line 750, in login
raise last_exception
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\”, line 739, in login
(code, resp) = self.auth(
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\”, line 662, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b’5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https:// support .google .com/mail/?p=BadCredentials j4-20020aa7c0c4000000b004847513929csm11835908edp.72 - gsmtp’)

code line that is the issue:
with smtplib.SMTP_SSL(“ com”, 465, context = context) as smtp:
__smtp.login(email_sender, email_password)
__smtp.sendmail(email_sender, email_receiver, em.as_string())

that error means your credentials are bad. Make sure that your username is correct and that you are using an App password and not the password you use to login to gmail.

1 Like

the username is obv. my e.mail which i checked multiply times.
As such i assume my password was wrong. I use the 2-step-authetification and got the app password.
i put it between “”, yet it still gives me the same error. :confused:

Hmm, try forking this and putting in your username and password. Or else you can try making a new app password.

Thank you, i´ll try to understand the code fully. It´s different than the one i learned.
If i may ask, what exactly does the “environ” function from the “os” lib do ?

os.environ is a dictionary of all the environment variables. When you create a replit secret it it added to that dictionary (to put it simply).
os.environ also contains handy stuff like:

REPL_OWNER → The username of the person running the repl
REPL_ID → the id of the repl
HOSTNAME → Hostname

And tons of other stuff. To see all the keys and values in os.environ run:

import os

for key in os.environ.keys():
    print(f"{key} -> {os.environ[key]}")

I see, thank you.
I´ll try to run it sometimes tomorrow ^^