为什么 MAPI 不能移动文件夹中的所有邮件?
Why MAPI can't move all mail in folder?
我创建了 zmq 客户端 python 脚本以与 zmq server.It 一起工作所有客户端都很好但是当我创建新的邮件文件夹以将完成工作(客户端)移动到此文件夹时。我使用 mail.Move 函数。它适用于一些客户。这是我的客户代码:
import zmq
import json
import win32com.client
import time
import os
context = zmq.Context()
print('Connecting to manager approve server…')
socket = context.socket(zmq.REQ)
socket.connect('tcp://localhost:5555')
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6).Folders.Item("1.Manager")
donembox = outlook.GetDefaultFolder(6).Folders.Item("1.1done_manager")
outlook = inbox.Items
mail = outlook.GetLast()
for mail in outlook:
if mail.Body == "Status: Manager Approved \r\n":
print('Inv number : '+str(mail.Subject))
socket.send_string(mail.Subject)
message = socket.recv()
time.sleep(1)
print('Inv number : '+str(mail.Subject) + " was moved to AP approval Process.")
time.sleep(1)
mail.Move(donembox)
print(str(mail.Subject)+ ' success.')
这是我的 zmq 服务器代码:
import time
import threading
import zmq
import win32com.client
import os, sys
import pyautogui as py
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind('tcp://*:5555')
print("Manager Server port 5555 Activate!")
while True:
message = socket.recv()
print('Received request: {}'.format(message))
time.sleep(20)
path = "R:/<my accounting team>/Project/Invoice form/Invoice_generate/"+str(message)+"/"+str(message)+".xlsm"
isExist = os.path.exists(path)
print(isExist)
if os.path.exists(path):
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(os.path.abspath(path))
xl.Application.Run("Module6.manager()")
xl.Application.Quit()
del xl
time.sleep(2)
py.click(599,392)
time.sleep(2)
socket.send_json({ 'status': 'ok' })
print('Reply')
print(path)
因为您正在修改(通过调用 MailItem.Move
)您正在处理的集合,因此您的代码将跳过一些项目。
将循环更改为反向 for 循环(从 Items.Count
减少到 1)。
我创建了 zmq 客户端 python 脚本以与 zmq server.It 一起工作所有客户端都很好但是当我创建新的邮件文件夹以将完成工作(客户端)移动到此文件夹时。我使用 mail.Move 函数。它适用于一些客户。这是我的客户代码:
import zmq
import json
import win32com.client
import time
import os
context = zmq.Context()
print('Connecting to manager approve server…')
socket = context.socket(zmq.REQ)
socket.connect('tcp://localhost:5555')
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6).Folders.Item("1.Manager")
donembox = outlook.GetDefaultFolder(6).Folders.Item("1.1done_manager")
outlook = inbox.Items
mail = outlook.GetLast()
for mail in outlook:
if mail.Body == "Status: Manager Approved \r\n":
print('Inv number : '+str(mail.Subject))
socket.send_string(mail.Subject)
message = socket.recv()
time.sleep(1)
print('Inv number : '+str(mail.Subject) + " was moved to AP approval Process.")
time.sleep(1)
mail.Move(donembox)
print(str(mail.Subject)+ ' success.')
这是我的 zmq 服务器代码:
import time
import threading
import zmq
import win32com.client
import os, sys
import pyautogui as py
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind('tcp://*:5555')
print("Manager Server port 5555 Activate!")
while True:
message = socket.recv()
print('Received request: {}'.format(message))
time.sleep(20)
path = "R:/<my accounting team>/Project/Invoice form/Invoice_generate/"+str(message)+"/"+str(message)+".xlsm"
isExist = os.path.exists(path)
print(isExist)
if os.path.exists(path):
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(os.path.abspath(path))
xl.Application.Run("Module6.manager()")
xl.Application.Quit()
del xl
time.sleep(2)
py.click(599,392)
time.sleep(2)
socket.send_json({ 'status': 'ok' })
print('Reply')
print(path)
因为您正在修改(通过调用 MailItem.Move
)您正在处理的集合,因此您的代码将跳过一些项目。
将循环更改为反向 for 循环(从 Items.Count
减少到 1)。