Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29758

How to schedule an email using dates from an sql Table in python

$
0
0

I want to send a Reminder to the users email that has their inputted text as the contents using the dates from a sql database that the user enters. I am getting the inputs from a PYQT Page but i wont need any help with that as ive got the inputs into a table.

This is my database:My Database

And this is the code i am using to get the information and the way i am sending emails at the moment.

    connection = sqlite3.connect("CURRENTUSER.db")     crsr = connection.cursor()     crsr.execute('SELECT User FROM USER WHERE ID = 1 ')    CurrentUser = crsr.fetchall()    CurrentUser = str([CurrentUser])    CurrentUser = CurrentUser.replace('[', '')    CurrentUser = CurrentUser.replace(']', '')    CurrentUser = CurrentUser.replace('(', '')    CurrentUser = CurrentUser.replace(')', '')    CurrentUser = CurrentUser.replace(',', '')    CurrentUser = CurrentUser.replace("'" , '')    connection = sqlite3.connect("Emaildatabase.db")     crsr = connection.cursor()     crsr.execute('SELECT Email FROM Email WHERE Username = ? ', (CurrentUser,))    Mail = crsr.fetchall()    Mail = str(Mail)    Mail = Mail.replace('[', '')    Mail = Mail.replace(']', '')    Mail = Mail.replace('(', '')    Mail = Mail.replace(')', '')    Mail = Mail.replace(',', '')    Mail = Mail.replace("'" , '')        ReminderDate = self.Reminder_Date.date().toPyDate()    DueDate = self.Due_Date.date().toPyDate()    ReminderTime = self.Reminder_Time.time().toString()    DueTime = self.Due_Time.time().toString()    ReminderDate = str(ReminderDate)    ReminderDate = ReminderDate.replace("-","/")    DueDate = str(DueDate)    DueDate = DueDate.replace("-","/")    Input = self.Info_Input.toPlainText()    Connection = sqlite3.connect("Reminders.db")    crsr = Connection.cursor()    crsr.execute ("SELECT ID FROM Reminder")    ID = crsr.fetchall()    IDLen = len(ID)    CurrentID = (IDLen + 1)    CurrentID = str([CurrentID])    CurrentID = CurrentID.replace('[', '')    CurrentID = CurrentID.replace(']', '')    CurrentID = CurrentID.replace('(', '')    CurrentID = CurrentID.replace(')', '')    CurrentID = CurrentID.replace(',', '')    CurrentID = CurrentID.replace("'", '')    Update = ("INSERT INTO Reminder (DueDate, ReminderDate, ReminderTime, DueTime, Text, ID) VALUES (?, ?, ?, ?, ?, ? )")    Values = [(DueDate, ReminderDate, ReminderTime, DueTime, Input, CurrentID)]    crsr.executemany(Update, Values)    Connection.commit()    yag = yagmail.SMTP('pythontest22222@gmail.com', 'phAR7b1H2uqII5G8YR')    contents = [" HElllOOOO"        ]    yag.send(Mail, 'Your Set Reminder', contents)

I did find a way to schedule emails but they were set using the code not using variables or SQL Data.

    send_time = dt.datetime(2018,8,26,3,0,0) # set your sending time in UTC    time.sleep(send_time.timestamp() - time.time())

I still dont know how to get the dates from the table to be then used by the the program to schedule the email.


Viewing all articles
Browse latest Browse all 29758

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>