Sending email with attachment for raspberry

python

#1

Hi guys,

i am trying to send e-mail with an attachment(Video file) via Raspberry Pi. But when i run the following code, there is always error. Please help me with this .

the error message :slight_smile:
Traceback (most recent call last):
File "python", line 21, in
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Bin.Lin\Desktop\securityVideo.h264'

============================================================================

emailing.py(my python script )

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 = "My E-mail Address"
toAddr = "other E-mail of Mine"

msg = MIMEMultipart()

msg['From'] = fromAddr
msg['To'] = toAddr
msg['Subject'] = "From Home Security System"

body = "Motion is Detected!! Someone is in your HOUSE!!"

msg.attach(MIMEText(body, 'plain'))

filename = "securityVideo.h264"
attachment = open(r"C:\Users\Bin.Lin\Desktop\securityVideo.h264", "rb")

part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachement; filename = %s" % filename)

msg.attach(part)

server = smtplib.SMTP('smtp.gmail.com', 587)
server.startttls()
server.login(fromAddr, "My Password")
text = msg.as_string()
server.sendmail(fromAddr, toAddr, text)
server.quit()


#2

The error is referring to the file path you are trying to get the video from. Either the video is not there or the file path is incorrect.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.