Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from email.mime.text import MIMEText
- from email.mime.multipart import MIMEMultipart
- from email.mime.base import MIMEBase
- from email import encoders
- import os
- files = []
- #Credentials
- sender_username = 'pythonmailertst@gmail.com'
- sender_password = 'testacc99'
- recipient_username = 'nasifistiak@gmail.com'
- subject = 'Python Test Email'
- body = 'Hello World.'
- fileDirectory = "FilesToSend/"
- numberOfFilesToPick = 2
- temp = []
- msg = MIMEMultipart()
- def msgInit():
- global msg
- msg = MIMEMultipart()
- msg['From'] = sender_username
- msg['To'] = recipient_username
- msg['Subject'] = subject
- msg.attach((MIMEText(body, 'plain')))
- msgInit()
- server = smtplib.SMTP('smtp.gmail.com', 587)
- server.starttls()
- server.login(sender_username, sender_password)
- def messageSenderFunc():
- text = msg.as_string()
- #server.sendmail(sender_username, recipient_username, text)
- msgInit()
- print(temp)
- temp.clear()
- def combinationUtil(arr, temp, start, end, index, r):
- if (index == r):
- for j in temp:
- msg.attach(j)
- messageSenderFunc()
- return
- i = start
- while (i <= end and end - i + 1 >= r - index):
- temp.append(arr[i])
- combinationUtil(arr, temp, i + 1, end, index + 1, r)
- i+=1
- fileCount=0
- for filename in os.listdir(fileDirectory):
- attachment = open(fileDirectory+filename, 'rb')
- part = MIMEBase('application', 'octet-stream')
- part.set_payload(attachment.read())
- encoders.encode_base64(part)
- part.add_header('Content-Disposition', 'attachment; filename= ' + filename)
- files.append(part)
- fileCount += 1
- combinationUtil(files, temp, 0, fileCount-1, 0, numberOfFilesToPick)
- server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement