Python 将Lotus Notes电子邮件移动到其他文件夹
在提取了一些电子邮件数据之后,我想用python将电子邮件移动到指定的文件夹中。我已经搜索过了,似乎还没有找到我需要的东西 以前有人这样做过吗 根据评论,我添加了我目前的逻辑,希望它能澄清我的问题。我在文件夹中循环,提取详细信息。完成后,我想将电子邮件移动到其他文件夹Python 将Lotus Notes电子邮件移动到其他文件夹,python,python-3.x,lotus-notes,win32com,Python,Python 3.x,Lotus Notes,Win32com,在提取了一些电子邮件数据之后,我想用python将电子邮件移动到指定的文件夹中。我已经搜索过了,似乎还没有找到我需要的东西 以前有人这样做过吗 根据评论,我添加了我目前的逻辑,希望它能澄清我的问题。我在文件夹中循环,提取详细信息。完成后,我想将电子邮件移动到其他文件夹 import win32com.client import getpass import re ''' Loops through Lotus Notes folder to view messages ''' def doc
import win32com.client
import getpass
import re
'''
Loops through Lotus Notes folder to view messages
'''
def docGenerator(folderName):
# Get credentials
mailServer = 'server'
mailPath = 'PubDir\inbox.nsf'
# Password
pw = getpass.getpass('Enter password: ')
# Connect
session = win32com.client.Dispatch('Lotus.NotesSession')
# Initializing the session and database
session.Initialize(pw)
db = session.GetDatabase(mailServer, mailPath)
# Get folder
folder = db.GetView(folderName)
if not folder:
raise Exception('Folder "%s" not found' % folderName)
# Get the first document
doc = folder.GetFirstDocument()
# If the document exists,
while doc:
# Yield it
yield doc
# Get the next document
doc = folder.GetNextDocument(doc)
# Loop through emails
for doc in docGenerator('Folder\Here'):
# setting variables
subject = doc.GetItemValue('Subject')[0].strip()
invoice = re.findall(r'\d+',subject)[0]
body = doc.GetItemValue('Body')[0].strip()
# Move email after extracting above data
# ???
由于您将在获取下一个文档之前移动该文档,因此我建议将您的循环替换为
doc = folder.GetFirstDocument()
while doc:
docN = folder.GetNextDocument(doc)
yield doc
doc = docN
然后将邮件移动到所需的适当文件夹
doc.PutInFolder(r"Destination\Folder")
doc.RemoveFromFolder(r"Origin\Folder")
当然,请注意转义反斜杠或使用原始字符串文字来正确传递视图名称
如果文件夹不存在,doc.PutInFolder将创建该文件夹。在这种情况下,用户需要具有创建公用文件夹的权限,否则创建的文件夹将是私有的。(当然,如果文件夹已经存在,这不是问题。)显示您的代码!如果您不知道使用哪种API来访问LotusNotes数据,没有人能为您回答这个问题。有些API公开了一个方法来做您想做的事情,有些则没有。