How to send Emails in CSV file and other types of files.


How to send Emails in CSV file and other types of files.

First Program to simple to send email in normal text message:-

import smtplib

a=input("Print message to send")
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('Enter Sender Email ID',"Passowrd for your email id")
server.sendmail('Enter Sender Email ID','Enter Reciver Email ID',a)
server.close()

print("Sucefully")



Second Program into to send Email in  CSV file and other type of files:-

import smtplib

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

fromaddr = "Enter Sender Emial"toaddr = "Enter Reciver Email"# instance of MIMEMultipartmsg = MIMEMultipart()
# storing the senders email addressmsg['From'] = fromaddr
# storing the receivers email addressmsg['To'] = toaddr
# storing the subjectmsg['Subject'] = "Enter subject"# string to store the body of the mailbody = "Enter body message"# attach the body with the msg instancemsg.attach(MIMEText(body, 'plain'))
# open the file to be sentfileName_email = "Attendance_" + ".csv"attachment = open("C:\\Users\\deepe\\Desktop\\Student attendance syatem\\Attendance\\" + fileName_email, "rb")
# instance of MIMEBase and named as pp = MIMEBase('application', 'octet-stream')
# To change the payload into encoded formp.set_payload((attachment).read())
# encode into base64encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % fileName_email)
# attach the instance 'p' to instance 'msg'msg.attach(p)
# creates SMTP sessions = smtplib.SMTP('smtp.gmail.com', 587)
# start TLS for securitys.starttls()
# Authenticationwith open('Enter Your Password File name ', 'r') as v: # You normaly enter your password    f_content = v.read()
    s.login(fromaddr, f_content)
#s.login(fromaddr, "Enter your password") # you not used to password file than to use# Converts the Multipart msg into a stringtext = msg.as_string()
# sending the mails.sendmail(fromaddr, toaddr, text)
# terminating the sessions.quit()



So, I hope you liked this content. Plz share your opiniyane for my bolog.
ThankYou.


Recommended for you :-

How to install packages in python using python program (code)?

How to install any OS in Amazon Web Services (AWS) .

How to use Amazon Web Services (AWS) instance(OS) in Windows using putty ?
how to add volume in aws instance and how to launch ec2 instance in aws.connect4 game Using java

STUDENT ATTENDANCE SYSTEM USING FACE ID

Comments