I'm trying to send multiple e-mails with different file attachments in each one.
Like this: file_A go to mail_a@mail.com file_B go to mail_b@mail.com ...
I tried this code, but when I'm looping though the dictionary all of my e-mails goes to mail_c@mail.com, instead of A to A, B to B, C to C as intended.
import pandas as pd
import shutil, os
import os
import tempfile
import win32com.client as win32
import glob, os
npath="yourpath/"
files=['file_a.xlsx','file_b.xlsx','file_c.xlsx']
mails=dict(zip(['mail_a@mail.com','mail_b@mail.com','mail_c@mail.com'],files))
for file in os.listdir(npath):
if file.endswith(".xlsx"):
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
for id,i in mails.items():
mail.To = id
mail.Subject = 'Test'
mail.HtmlBody = 'testing'
mail.Attachments.Add(os.path.join(npath,file))
mail.Display()
I'm pretty sure my problem is this loop or my dictionary, but after trying for hours couldn't solve by my self.
for id,i in mails.items():
print(id)
mail.To = id