Python : 如何访问 Lotus Notes 8.5 收件箱以阅读电子邮件
Python : How can I access Lotus Notes 8.5 Inbox to read emails
我想在 python 中创建一个脚本,从 Lotus Notes 8.5 读取邮件,然后在 jira 中为每封邮件创建一个问题,但是 returns 当我尝试阅读来自 Lotus 的邮件:
Traceback (most recent call last):
File "from_Lotus_TO_Jira.py", line 46, in <module>
main()
File "from_Lotus_TO_Jira.py", line 39, in main
folder = notesDatabase.GetView('$Inbox')
File "C:\Python27\lib\site-packages\win32com\gen_py131520-2EED-1069-BF5D-00
DD011186B7x0x1x2.py", line 1849, in GetView
ret = self._oleobj_.InvokeTypes(1610743866, LCID, 1, (9, 0), ((8, 1),),pName
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'NotesDatabase',
u'Database server_name!!C:\Users\MYNAME\AppData\Local\Lotus\Notes\Data\ma
il202\myname.nsf has not been opened yet', None, 0, -2147217441), None)
这是我的 .py 文件
import win32com.client
import pywintypes
import getpass
def main():
# Get credentials
mailServer = 'server_name'
mailPath = 'C:\Users\MYNAME\AppData\Local\Lotus\Notes\Data\mail202\myname.nsf'
mailPassword = ''
# Connect
notesSession = win32com.client.Dispatch('Lotus.NotesSession')
notesSession.Initialize(mailPassword)
notesDatabase = notesSession.GetDatabase(mailServer, mailPath)
# Get a list of folders
folder = notesDatabase.GetView('$Inbox')
document = folder.GetFirstDocument()
if __name__ == "__main__":
main()
正在查看http://www-01.ibm.com/support/docview.wss?uid=swg21308538
The full filepath (e.g. "C:\notes\data\r_apps\haha.nsf") may
optionally be used when accessing local databases on a workstation. If
you specify a server name, however, or if the code is running on a
server, you must use the path relative to the Notes data directory
("r_apps\haha.nsf").
我建议 (a) 不指定服务器或 (b) 只给出相对路径,即 mailPath = r'mail202\myname.nsf'
。
您正在使用 Notes COM 类。打开当前用户的邮件数据库有一个很好的快捷方式调用。 NotesSession class contains a GetDbDirectory method, which returns a NotesDbDirectory object, and the NotesDbDirectory class contains an OpenMailDatabase method.
我不是 Python 人所以我不能保证确切的语法,但它应该是这样的:
notesSession.Initialize(mailPassword)
notesDbDirectory = notesSession.GetDbDirectory('')
notesDatabase = NotesDbDirectory.GetMailDatabase()
请注意,GetDbDirectory 的参数可以是空字符串或 Domino 服务器的名称。它应该没有任何区别,因为 GetMailDatabase 方法遵循与 NotesDatabase.OpenMail method 相同的过程(它不通过 COM 接口公开,因此它对 Python 不可用)。即,它会查看当前用户的 Notes 客户端配置,以找到用户邮件数据库的 server-based 或本地副本。
另请注意,如果此代码旨在 运行 在一台机器上但在一台 Domino 服务器上为许多用户处理邮件,则您不能使用 GetMailDatabase 方法。在那种情况下,使用@Hugh-Bothwell 的答案中的相对路径是正确的,尽管我强烈建议通过调用 notesDatabase.IsOpen() 在调用 [=11] 之间添加一些防御性编程=] 和 GetView()
.
我想在 python 中创建一个脚本,从 Lotus Notes 8.5 读取邮件,然后在 jira 中为每封邮件创建一个问题,但是 returns 当我尝试阅读来自 Lotus 的邮件:
Traceback (most recent call last):
File "from_Lotus_TO_Jira.py", line 46, in <module>
main()
File "from_Lotus_TO_Jira.py", line 39, in main
folder = notesDatabase.GetView('$Inbox')
File "C:\Python27\lib\site-packages\win32com\gen_py131520-2EED-1069-BF5D-00
DD011186B7x0x1x2.py", line 1849, in GetView
ret = self._oleobj_.InvokeTypes(1610743866, LCID, 1, (9, 0), ((8, 1),),pName
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'NotesDatabase',
u'Database server_name!!C:\Users\MYNAME\AppData\Local\Lotus\Notes\Data\ma
il202\myname.nsf has not been opened yet', None, 0, -2147217441), None)
这是我的 .py 文件
import win32com.client
import pywintypes
import getpass
def main():
# Get credentials
mailServer = 'server_name'
mailPath = 'C:\Users\MYNAME\AppData\Local\Lotus\Notes\Data\mail202\myname.nsf'
mailPassword = ''
# Connect
notesSession = win32com.client.Dispatch('Lotus.NotesSession')
notesSession.Initialize(mailPassword)
notesDatabase = notesSession.GetDatabase(mailServer, mailPath)
# Get a list of folders
folder = notesDatabase.GetView('$Inbox')
document = folder.GetFirstDocument()
if __name__ == "__main__":
main()
正在查看http://www-01.ibm.com/support/docview.wss?uid=swg21308538
The full filepath (e.g. "C:\notes\data\r_apps\haha.nsf") may optionally be used when accessing local databases on a workstation. If you specify a server name, however, or if the code is running on a server, you must use the path relative to the Notes data directory ("r_apps\haha.nsf").
我建议 (a) 不指定服务器或 (b) 只给出相对路径,即 mailPath = r'mail202\myname.nsf'
。
您正在使用 Notes COM 类。打开当前用户的邮件数据库有一个很好的快捷方式调用。 NotesSession class contains a GetDbDirectory method, which returns a NotesDbDirectory object, and the NotesDbDirectory class contains an OpenMailDatabase method.
我不是 Python 人所以我不能保证确切的语法,但它应该是这样的:
notesSession.Initialize(mailPassword)
notesDbDirectory = notesSession.GetDbDirectory('')
notesDatabase = NotesDbDirectory.GetMailDatabase()
请注意,GetDbDirectory 的参数可以是空字符串或 Domino 服务器的名称。它应该没有任何区别,因为 GetMailDatabase 方法遵循与 NotesDatabase.OpenMail method 相同的过程(它不通过 COM 接口公开,因此它对 Python 不可用)。即,它会查看当前用户的 Notes 客户端配置,以找到用户邮件数据库的 server-based 或本地副本。
另请注意,如果此代码旨在 运行 在一台机器上但在一台 Domino 服务器上为许多用户处理邮件,则您不能使用 GetMailDatabase 方法。在那种情况下,使用@Hugh-Bothwell 的答案中的相对路径是正确的,尽管我强烈建议通过调用 notesDatabase.IsOpen() 在调用 [=11] 之间添加一些防御性编程=] 和 GetView()
.