J'ai essayé cet email envoyer sample code:ImportError: charge DLL:% 1 n'est pas une application Win32 valide lors de l'importation win32com
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 21 15:36:00 2016
@author: Deepesh.Singh
"""
import win32com.client as win32
import psutil
import os
import subprocess
# Drafting and sending email notification to senders. You can add other senders' email in the list
def send_notification():
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]; [email protected]',
mail.Subject = 'Sent through Python'
mail.body = 'This email alert is auto generated. Please do not respond.'
mail.send
# Open Outlook.exe. Path may vary according to system config
# Please check the path to .exe file and update below
def open_outlook():
try:
subprocess.call(['C:\Program Files\Microsoft Office\Office15\Outlook.exe'])
os.system("C:\Program Files\Microsoft Office\Office15\Outlook.exe");
except:
print("Outlook didn't open successfully")
# Checking if outlook is already opened. If not, open Outlook.exe and send email
for item in psutil.pids():
p = psutil.Process(item)
if p.name() == "OUTLOOK.EXE":
flag = 1
break
else:
flag = 0
if (flag == 1):
send_notification()
else:
open_outlook()
send_notification()
mais continuer à frapper l'erreur suivante lorsque je lance le code sur l'invite de commande:
C:\<>\Desktop\Exp>python sendemail.py
Traceback (most recent call last):
File "sendemail.py", line 40, in <module>
import win32com.client
File "C:\Python27\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: %1 is not a valid Win32 application.
Quelqu'un peut-il me guider sur la façon de corriger cette erreur? Ou est-ce leur meilleur moyen de le faire?
Merci.
s'il vous plaît dites à votre version python et bit? et OS? – Harsha
Python 2.7.13 (v2.7.13: a06454b1afa1, 17 déc 2016, 20:42:59) [MSC v.1500 32 bits (Intel)] sur win32. J'utilise Windows 10 64 bits OS – Khan
J'ai réinstallé pywin32 (version 32 bits) comme indiqué par Trapli ci-dessous et également installé le module psutil et redémarré mon système. Le problème est résolu maintenant et je peux envoyer un courriel. Merci à tous de m'avoir aidé. – Khan