Sinisterly
Adding a sleep or delay function to a Python script - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Python (https://sinister.li/Forum-Python)
+--- Thread: Adding a sleep or delay function to a Python script (/Thread-Adding-a-sleep-or-delay-function-to-a-Python-script)



Adding a sleep or delay function to a Python script - xdlwilliamz - 04-17-2020

I have got a couple of Python mailing scripts but trying to figure out a way to alter the scripts so it sends out mail from a mailing list one after the other instead of all at once, maybe like a few seconds delay after each mail is sent, i could upload the scripts here for a closer look if required...


RE: Adding a sleep or delay function to a Python script - mothered - 04-18-2020

Thread moved from The Lounge forum, accordingly to Python.


RE: Adding a sleep or delay function to a Python script - Blue - 04-18-2020

Can you post your code in a code sample for us?
That way we can give you an example of something that might work for you.


RE: Adding a sleep or delay function to a Python script - xdlwilliamz - 04-18-2020

(04-18-2020, 05:41 AM)Blue Wrote: Can you post your code in a code sample for us?
That way we can give you an example of something that might work for you.
Code:
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.base import MIMEBase from email import encoders email_user = 'your_email' email_password = 'your_password' email_send = 'recipient_email' subject = 'subject' msg = MIMEMultipart() msg['From'] = email_user msg['To'] = email_send msg['Subject'] = subject body = 'Hi there, sending this email from Python!' msg.attach(MIMEText(body,'plain')) filename='filename' attachment =open(filename,'rb') part = MIMEBase('application','octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header('Content-Disposition',"attachment; filename= "+filename) msg.attach(part) text = msg.as_string() server = smtplib.SMTP('smtp.gmail.com',587) server.starttls() server.login(email_user,email_password) server.sendmail(email_user,email_send,text) server.quit()



RE: Adding a sleep or delay function to a Python script - slothic - 04-18-2020

Code:
import time time.sleep(1) #sleeps for 1second then continues



RE: Adding a sleep or delay function to a Python script - Crown - 09-11-2020

time.sleep(secondshere)

would be easy way to do it.