Sending email with attachment for raspberry



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'

============================================================================ 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.add_header('Content-Disposition', "attachement; filename = %s" % filename)


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


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.


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