Untitled
unknown
plain_text
2 years ago
2.0 kB
10
Indexable
import Con import smtplib from email.mime.text import MIMEText from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication import config import pandas as pd import csv server=smtplib.SMTP('smtp.gmail.com',587) server.starttls() server.login("surajkesarwani2@gmail.com",config.gmailpass) subject="This is my Test email for Checking flow of db to csv" s=Con.db ab=s.cursor() query="select Name, Age from data230" ab.execute(query) All_data=ab.fetchall() name=[] age=[] for Name ,Age in All_data: name.append(Name) age.append(Age) # print("Name is =",name," and " ," Age is =",Age) df={ 'Name ':name, 'Age':age } dt=pd.DataFrame(df) dt_csv=dt.to_csv("data.csv") msg='''Hello \n This is my test email for checking the flow of data coming from db which passes through gmail \n let me know sir if need to make any changes in it Regards, Suraj ''' sender="surajkesarwani2@gmail.com" rec="surajkesarwani2@gmail.com" mssg=MIMEMultipart() mssg["From"]=sender mssg["to"]=rec mssg["subject"]=subject mssg.attach(MIMEText(msg,'plain')) with open('download.jpeg', 'rb') as fp: img = MIMEImage(fp.read()) img.add_header('Content-Disposition', 'attachment', filename="download.jpeg") mssg.attach(img) with open('img.jpeg', 'rb') as pl: img = MIMEImage(pl.read()) img.add_header('Content-Disposition', 'attachment', filename="img.jpeg") mssg.attach(img) with open("data.csv",'rb')as sata: attachment=MIMEApplication(sata.read()) # encoders.encode_base64(attachment) attachment.add_header('Content-Disposition', "attachment", filename="data.csv") mssg.attach(attachment) with open("data23.csv","rb")as kata: atta=MIMEApplication(kata.read()) atta.add_header("Content-Disposition", "attachment", filename="data.csv") mssg.attach(atta) server.send_message(mssg) server.close()
Editor is loading...