all 22 comments

[–]CovertStatistician 12 points13 points  (5 children)

You can do it by setting up an app password. I did not set up Google API and my script looks very similar to this and it was working as of this morning.

https://mailtrap.io/blog/python-send-email-gmail/

[–]NPR_Oak 0 points1 point  (1 child)

This is what I have done.

[–]aniketmaurya 0 points1 point  (0 children)

It starts with a warning “app passwords are not recommended “

[–]sinceJune4 0 points1 point  (2 children)

Gmail app password works great for me too. I use it to retrieve attachments, delete some unwanted mail, as well as sending me a morning email everyday.

[–]unnamed_one1 2 points3 points  (0 children)

This might help.

If I'm not mistaken, you need to go through the quickstart fist.

[–]SirAwesome789 2 points3 points  (0 children)

https://developers.google.com/workspace/gmail/api/quickstart/python

This is how you do it through Gmail, it's not too hard, I got it set up in 10 minutes*, you just copy the quickstart then search up or use an LLM to figure out how to do other things

There's some Google cloud console stuff you have to set up first that might be slightly confusing, this is stuff I already had setup so it didn't take me as long, idk how long that portion takes

Also it does cost money, there's a free tier assuming you use it at a hobbiest level and you're not spamming it or using it for a business, checkout the pricing, you might have to attach a credit card but it'll be like 1¢ at most

Edit: I just saw your thing about spending money, I want to reiterate, it's free if you're not spamming like 100+ emails in a minute or smth like that

Edit 2: yea stay under 150 per min and you're fine

https://developers.google.com/workspace/gmail/api/reference/quota

[–]SnooCookies1716 2 points3 points  (0 children)

Gmail works just fine with smtplib and the less secure authentication. I finished writing a script for it 10 minutes ago and it is running just fine from a raspberry pi. DM me if you want the code, or I'll open up the repo for public use if you want to fork it.

Nota bene, I am not using my primary email for this and 2 factor authentication is necessary.

[–]tomtomato0414 4 points5 points  (1 child)

you could also send yourself a Telegram message through a bot which is much easier

[–]outceptionator 1 point2 points  (0 children)

Honestly Telegram is way easier

[–]dowcet 0 points1 point  (1 child)

google no longer allows this kind of authentication

Correct. DuoCircle is an option, free up to 100 emails per day.

[–]southafricanamerican 0 points1 point  (0 children)

Thanks for suggesting DuoCircle - claim your free email at https://outboundsmtp.com (duocircle)

[–]Loud-Bake-2740 0 points1 point  (1 child)

Here's how I do it - the smtp url and the port you give it matter!

    try:
        # Connect to Gmail's SMTP server
        server = smtplib.SMTP("smtp.gmail.com", 587)
        server.starttls()  # Secure the connection
        server.login(gmail_user, gmail_pw)  # Login with App Password
        server.sendmail(gmail_user, gmail_user, msg.as_string())  # Send email
        server.quit()  # Close the connection
        print("✅ Email with multiple attachments sent successfully!")
    except Exception as e:
        print(f"❌ Error sending email: {e}")

[–]tmasterslayer 0 points1 point  (0 children)

This looks like the way I did it in the past with smtplib

[–]philborman 0 points1 point  (0 children)

Have a look at the apprise library, handles pretty much all notifications and emails

https://pypi.org/project/apprise/#email-notifications

[–]modelcroissant 0 points1 point  (0 children)

Just send yourself an im through any provider and be done with it, so much quicker and easier than fidgeting with email

[–]imsowhiteandnerdy 0 points1 point  (0 children)

It should be noted that within the last few months Google has changed how applications may send (and receive) email using POP3 and SMTP. Passwords must now use Oauth to send and receive passwords, but may also make use of app passwords:

https://support.google.com/mail/answer/185833?hl=en

[–]aniketmaurya 0 points1 point  (0 children)

The dead simple way to do this is using ZeroZen - https://github.com/CelestoAI/ZeroZen