I am a newbie to python, I would like to create an application that can send all files from a folder.
anyidea to get all files from a folder and send email to someone
in example, there are four files from my folder, and I would to get all files from a folder Thank you very much
Folder
-AAA.txt
-BBB.zip
-CCC.docx
-av.mp4
my code
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
mail_host="smtp.gmail.com"
mail_user="testing"
mail_pass="testing"
sender = 'testing@gmail.com'
receivers = ['testing@gmail.com']
message = MIMEMultipart()
message['From'] = Header("Hello2", 'utf-8')
message['To'] = Header("World2", 'utf-8')
subject = 'Python SMTP Testing'
message['Subject'] = Header(subject, 'utf-8')
att1 = MIMEText(open('folder/*', 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
att1["Content-Disposition"] = 'attachment; filename="test.txt"'
message.attach(att1)
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25)
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print('Sent...')
except:
traceback.print_exc()
print('Error: ')