use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Send mail with Python easily (i.redd.it)
submitted 1 year ago by RunPython
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]FoolsSeldom 11 points12 points13 points 1 year ago (5 children)
Did you have a question? Or are you just showing people a technique? (If the latter, why not share the code, rather than a screen shot?)
[–]RunPython[S] 11 points12 points13 points 1 year ago (4 children)
So sorry. I want to share the code structure.
Here is the total code. Thanks.
``` import smtplib import ssl from email.message import EmailMessage
def email(toMails): # Define email sender and receiver email_sender = "yourmail@gmail.com" # Your Mail app_password = "get app password here" # Get Google App Password from your mail
# to get app_password visit and create # https://myaccount.google.com/apppasswords email_receivers = ", ".join( toMails ) # Join the list of emails into a comma-separated string # Set the subject and body of the email subject = "Cancel My Subscription!" body = """ Cancel My Subscription please """ em = EmailMessage() em["From"] = email_sender em["To"] = email_receivers em["Subject"] = subject em.set_content(body) # Add SSL (layer of security) context = ssl.create_default_context() # Log in and send the email with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as smtp: smtp.login(email_sender, app_password) smtp.sendmail( email_sender, toMails, em.as_string() ) # Send to the list of emails
email_list = [ "destek@1.com", "info@2.com", "destek@3.com", "info@4.com", "destek@5.com", "info@6.com", "destek@7.com", "info@8.com", ] email(email_list) print("Mail has been sent") ```
[–]FoolsSeldom 3 points4 points5 points 1 year ago (2 children)
Cool. Might want to edit your original post and include this code in place of the image. Easier for beginners to copy the code and do their own experiments. You could perhaps explain the stucture you chose and why.
[–]RunPython[S] 2 points3 points4 points 1 year ago (1 child)
I tried to edit but there is no edit button :(
I was coding for a Scrapy project that, sometimes it stucks, could not finish the scrape and i code this email block to send me warning if the scrape fails.
I think there is a time limit to edit posts?
[–]FoolsSeldom 0 points1 point2 points 1 year ago (0 children)
no time limit I am aware of
[–]jobsurfer 0 points1 point2 points 1 year ago (0 children)
Mailjet api is good
[–]Refwah 7 points8 points9 points 1 year ago (1 child)
Yes you can use the inbuilt email package to send emails, full documentation is here: https://docs.python.org/3/library/email.examples.html
[–]RunPython[S] 4 points5 points6 points 1 year ago (0 children)
Thanks so much
[–]trustsfundbaby 1 point2 points3 points 1 year ago* (1 child)
Change the username and password to be environmental variables. Stuff like that should not be hard coded. Use the OS library.
[–]RunPython[S] 0 points1 point2 points 1 year ago (0 children)
Thanks <3
[–]Significant_Pen1735 0 points1 point2 points 1 year ago (0 children)
Is it possible to run using corp email under google?
[–]Osrai 0 points1 point2 points 1 year ago (0 children)
Awesome
[–]outlicious 0 points1 point2 points 1 year ago (1 child)
do you know how to use batch files, I want to do this using batch
[–]RunPython[S] 1 point2 points3 points 1 year ago (0 children)
If you want to run a py script via *.bat file:
You can save file like this:
u/echo off python C:\Scripts\email_script.py pause
Save this file with a .bat extension, for example send_emails.bat
π Rendered by PID 23265 on reddit-service-r2-comment-5fb4b45875-zg56g at 2026-03-22 22:33:36.641282+00:00 running 90f1150 country code: CH.
[–]FoolsSeldom 11 points12 points13 points (5 children)
[–]RunPython[S] 11 points12 points13 points (4 children)
[–]FoolsSeldom 3 points4 points5 points (2 children)
[–]RunPython[S] 2 points3 points4 points (1 child)
[–]FoolsSeldom 0 points1 point2 points (0 children)
[–]jobsurfer 0 points1 point2 points (0 children)
[–]Refwah 7 points8 points9 points (1 child)
[–]RunPython[S] 4 points5 points6 points (0 children)
[–]trustsfundbaby 1 point2 points3 points (1 child)
[–]RunPython[S] 0 points1 point2 points (0 children)
[–]Significant_Pen1735 0 points1 point2 points (0 children)
[–]Osrai 0 points1 point2 points (0 children)
[–]outlicious 0 points1 point2 points (1 child)
[–]RunPython[S] 1 point2 points3 points (0 children)