I try to send 3 emails,through outlook, to 3 different people (with python 3) that contain pdf file attached. In key 12 I have 2 values, so when i run it while "secNum" variable is 12, the code send the email only to test2@gmail.com and not to test1@gmail.com.
How can i send the email to both people in key 12 using Python 3?
# -*- coding: cp1255 -*-
# encoding = utf8
import os,re,subprocess,time,win32com.client as win32
secNum = input()
dict1 = {'12': ['joe','zeelo' ]
'14': 'steeve'}
dict2 = {'12':'test1@gmail.com','test2@gmail.com',
'14':'test1@gmail.com'}
newDate = '27_06'
rootdir = r'F:\desktop\Project'
def data(listName):
return listName[secNum]
for rootdir, dirs, files in os.walk(rootdir):
for subdir in dirs:
folderPath = os.path.join(rootdir, subdir)
match = re.search('report'+ ' ' + secNum ,folderPath)
if match:
match2 = re.search('2022.June.'+ newDate ,folderPath)
if match2:
for fname in os.listdir(folderPath):
if fname.endswith('.pdf'): # -------
filePath = os.path.join(folderPath,fname)
print (filePath)
if secNum:
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.Subject = ' report:' +' ' + secNum
mail.To = data(dict2)
attachment = mail.Attachments.Add(filePath)
mail.HTMLBody = 'hi ' + data(dict1) + '<br> this is report date: <br/>' + newDate
mail.Send()