How do i add a document attachment when sending an email with python ? i get the email to send (please ignore: i am looping the email to send every 5 seconds, only for testing purposes, i want it to send every 30 min, just have to change 5 to 1800)
here is my code so far. how do i attach a document from my computer?
#!/usr/bin/python
import time
import smtplib
while True:
TO = '[email protected]'
SUBJECT = 'Python Email'
TEXT = 'Here is the message'
gmail_sender = '[email protected]'
gmail_passwd = 'xxxx'
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(gmail_sender, gmail_passwd)
BODY = '\n'.join([
'To: %s' % TO,
'From: %s' % gmail_sender,
'Subject:%s' % SUBJECT,
'',
TEXT
])
try:
server.sendmail(gmail_sender,[TO], BODY)
print 'email sent'
except:
print 'error sending mail'
time.sleep(5)
server.quit()
part.add_header('Content-Disposition', 'attachment; filename="WorkBook3.xlsx"')
where I would like to add files from the parameter list then the filename itself e.gpart.add_header('Content-Disposition', 'attachment; filename=files')
– Mortification