Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- import os,email
- from email.MIMEMultipart import MIMEMultipart
- from email.MIMEBase import MIMEBase
- from email.MIMEText import MIMEText
- #from email.Utils import COMMSPACE,formatdate
- from email import Encoders
- def send_mail(send_from, send_to, subject, text, file):
- msg = MIMEMultipart()
- msg['From'] = send_from
- msg['To'] = send_to
- msg['Date'] = " Use any date time module to insert or use email.utils formatdate"
- msg['Subject'] = subject
- msg.attach( MIMEText(text) )
- open(file, 'rb') as fp:
- msg = MIMEBase('application', "octet-stream")
- msg.set_payload(fp.read())
- encoders.encode_base64(msg)
- msg.add_header('Content-Disposition', 'attachment', filename=os.path.basename(file))
- outer.attach(msg)
- smtp = smtplib.SMTP("smtp.gmail.com",587)
- smtp.ehlo()
- smtp.starttls
- smtp.ehlo()
- smtp.login("raspberrypi.camera.project@gmail.com","PassWord12")
- sent=smtp.sendmail(send_from, send_to, msg.as_string())
- smtp.close()
- return sent
- s=send_mail("raspberrypi.camera.project@gmail.com","emese.mathe.07@gmail.com","Mail test","Message","/home/pi/video.h624")
- if (s.keys()==[]):
- print "Message Sent!!!!!!!!!"
- else:
- print "Error!!!!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement