I am trying to get only text files and images from a folder be sent as an attachment so far I can only get it to work with one extension and I tried this below but it doesnt work
types = ('*.txt', '*.png')
files =glob.glob( os.path.join(path,types))
for f in files:
part = MIMEBase('application', "octet-stream")
part.set_payload( open(f,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
msg.attach(part)
I got the following errors
files =glob.glob( os.path.join(path,types))
File "C:\Python27\lib\ntpath.py", line 73, in join
elif isabs(b):
File "C:\Python27\lib\ntpath.py", line 58, in isabs
return s != '' and s[:1] in '/\\'
TypeError: 'in <string>' requires string as left operand, not tuple