当试图将电子邮件从收件箱移动到另一个文件夹时,我对执行质量的执行质量有问题。
inbox = inbox.Items
example_folder = inbox.Restrict("[SenderEmailAddress] = '[email protected]'")
for message in example_folder:
message.Move(folder)
问题不是每个电子邮件在命令时都会移动,而是对sendername,主题和其他人也会发生同样的情况,因此这不是我要提取的电子邮件。它确实有效,但是我需要继续执行它才能捕获错过的那些。
代码有什么建议吗?如果没有,我是否有办法添加新代码,该代码只能自动重复该命令,直到我要停止? (一旦所有电子邮件都移动)。
I have an issue with the execution quality with the below code when trying to move emails from inbox to another folder.
inbox = inbox.Items
example_folder = inbox.Restrict("[SenderEmailAddress] = '[email protected]'")
for message in example_folder:
message.Move(folder)
The problem is not every email will move when commanded, same happens for SenderName, Subject, and others so it's not what I'm extracting the emails by. It does work, but I need to keep executing it to catch the ones it missed.
Any suggestions to the code? If not, is there a way for me to add new code that just repeats the command automatically until i want it to stop? (once all emails have been moved).
发布评论
评论(3)
首先,我建议您改用反向循环,请参见“ nofollow noreferrer”>向后迭代python 有关此的更多信息。
其次,我建议检查是否使用
限制
方法检查所有必需的项目。您的收集可能不包含您期望将所有项目移至文件夹中的所有项目。因此,在调试器下运行代码并比较发现多少项目并将其移至文件夹是有意义的。First of all, I'd recommend using the reversed for loop instead, see Backward iteration in Python for more information on that.
Second, I'd suggest checking whether all the required items are found using the
Restrict
method. Your collection may not contain all items you expect to be moved to the folder. So, it makes sense to run the code under the debugger and compare how many items are found and moved to the folder.您正在修改(通过调用
移动
)您要迭代的收集,这可能会导致某些项目被跳过。从itemss.count
向后使用向后进行循环,向下循环。You are modifying (by calling
Move
) the very collection you are iterating over, this can result in some items being skipped. Use a backward for loop fromItems.Count
down to 1.您在代码中有两个问题,当项目从收集最佳选项移动时是从结束开始,然后向后转到索引0
例如使用reversed() function with the range()函数,在reversed()方法 内包装range()方法
第二个问题是您的过滤器,
[senderemailAddress] 似乎可以正常工作
emailType =“ smtp”
,但对于Exchangeuser
尝试使用不同的过滤器示例
You have two issues in your code, When moving items from collection best option is to start at the end and go backwards to index 0
for example use the reversed() function with the range() function, Wrap the range() method inside the reversed() method
The second issue is your filter,
[SenderEmailAddress]
it seems to workEmailType = "SMTP"
but not forExchangeUser
try using different filterExample