Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How do I schedule an email to send at a certain time using cron and smtp, in python

import datetime as dt
import time
import smtplib

def send_email():
    email_user = 'myemail@gmail.com'
    server = smtplib.SMTP ('smtp.gmail.com', 587)
    server.starttls()
    server.login(email_user, 'email pass')

    #EMAIL
    message = 'sending this from python!'
    server.sendmail(email_user, email_user, message)
    server.quit()

send_time = dt.datetime(2018,8,26,3,0,0) # set your sending time in UTC
time.sleep(send_time.timestamp() - time.time())
send_email()
print('email sent')
Comment

PREVIOUS NEXT
Code Example
Python :: plotly scatter facet change labels 
Python :: matplotlib pie edge width 
Python :: Install pygmt in Anaconda prompt 
Python :: how to convert a string to a list python 
Python :: how to check if object is of file type in python3 
Python :: does tuple allow duplicate values in python 
Python :: pdf to excel conversion using python 
Python :: tkinter set text 
Python :: python check if attribute exists in dictionary 
Python :: # read table data from PDF into dataframe and save it as csv or json 
Python :: numpy savetext in one line 
Python :: feature importance plot using lasso regression 
Python :: recursive python 
Python :: python enumerate() 
Python :: STATPC 
Python :: pd df replace 
Python :: autokeras import colab 
Python :: how to slice a set in python 
Python :: why python stops after plt.show() 
Python :: Average of total in django querysets 
Python :: python array linspace 
Python :: how to uninstall python-dotenv 
Python :: how to sort dataframe in python by length of groups 
Python :: Returns a DataFrame representing the result of the given query 
Python :: py random.sample 
Python :: python manually trigger exception 
Python :: python yield from 
Python :: keras functional api embedding layer 
Python :: pandas find column with max value for each row 
Python :: histogram relative frequency 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =