I created an application from Python using Nuitka, and when running a distribution in a different PC the function of sending emails with an attachment is not working using pywin32. The following exemption is shown:
Failed to send email: (-2147352567, Exemption occured, (4096, Microsoft Outlook’ The access route doesn’t exist. Corroborate the the access route is correct, None, 0, -2147024893), None)
The executable is working appropriately in the development PC including the mail function.
import win32com.client
import pythoncom
def Send_mail():
try:
pythoncom.CoInitialize() # Ensure COM initialization
# destination = email_entry.get()
ol = win32com.client.Dispatch('Outlook.Application')
# size of the new email
olmailitem = 0x0
newmail = ol.CreateItem(olmailitem)
newmail.Subject = 'Test'
newmail.To = ';'.join(recipient_emails)
#newmail.CC = '[email protected]'
newmail.Body= 'Hello'
attach = 'file.xlsx' # File created with script, stored in executable folder
newmail.Attachments.Add(attach)
newmail.Display()
# Clear recipient email list
recipient_emails.clear()
except Exception as e:
# Show error message if any exception occurs
messagebox.showerror("Error", f"Failed to send email: {str(e)}")
def add_email():
email = email_entry.get().strip()
if email:
recipient_emails.append(email)
email_entry.delete(0, tk.END)
tree_mail.insert('', tk.END, values=email)
3