Python で Outlook 2007 の自動化を開始しようとしています。この素晴らしいスクリプト (以下) を Steve Townsend からこのスレッドで入手しました: Send Outlook Email Via Python?
しかし、私はこれを始めるのに苦労しています。
import win32com.client
def send_mail_via_com(text, subject, recipient, profilename="Outlook2007"):
s = win32com.client.Dispatch("Mapi.Session")
o = win32com.client.Dispatch("Outlook.Application")
s.Logon(profilename)
Msg = o.CreateItem(0)
Msg.To = recipient
Msg.CC = "moreaddresses here"
Msg.BCC = "address"
Msg.Subject = subject
Msg.Body = text
#attachment1 = "Path to attachment no. 1"
#attachment2 = "Path to attachment no. 2"
#Msg.Attachments.Add(attachment1)
#Msg.Attachments.Add(attachment2)
Msg.Send()
send_mail_via_com("test text","test subject", "removed@security.obv","Outlook2007")
しかし、次のエラーが発生します。
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 83, in _
GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\PROJECTS\Python\send_mail_test.py", line 25, in <module>
send_mail_via_com("test text","test subject", "removed@security.obv","Outloo
k2007")
File "C:\PROJECTS\Python\send_mail_test.py", line 4, in send_mail_via_com
s = win32com.client.Dispatch("Mapi.Session")
File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 95, in
Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
lsctx)
File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 108, in
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 85, in _
GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
D_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
それはおそらく私が見逃したばかげたものです。
Python 3.2 で、PyWin32 がインストールされています
どうもありがとう