Hi I want to make a script that sends some excel files stored in a folder one by one to a email address. But I seem to be getting an error.
Email_A = row['ICO Mail A']
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = Email_A
mail.Subject = 'Message subject'
mail.Body = 'Message body'
mail.HTMLBody = '<h2>HTML Message body</h2>' #this field is optional
# To attach a file to the email (optional):
attachment = (r"C:\Users\Username\Desktop\Work\Automation\SAP_output_scen1\*.xlsx")
for f in attachment:
mail.Attachments.Add(attachment)
mail.Send()
com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'File name or directory name is not valid.', None, 0, -2147024773), None)