如何使用 Python imaplib 将消息从一个 imap 服务器复制到另一个 imap 服务器?
我想将邮件从一台 IMAP 服务器复制到另一台 IMAP 服务器。我不想更改任何消息数据。我正在使用 python imaplib。
这是我尝试过的代码:
typ, data = connection1.uid('FETCH', uid, 'RFC822')
connection2.uid('APPEND', None, data[0][1])
但这引发了一个异常:
imaplib.error:UID 命令错误:BAD ['"交付至:[电子邮件受保护]']
因此,我认为参数 (data[0][1]) 的格式不正确,
data[0][1] 的内容如下所示:
发送至:[电子邮件受保护]\r\n已接收:通过 10.216.207.222,SMTP ID n27cs38120weo;\r\n星期五,2010 年 11 月 12 日 09:43:47 -0800 (PST)\r\n收到:通过 10.200.19.19,SMTP ID y19mr234526eba.52.12894526694 ;\r\n11 月 12 日星期五2010 09:43:46 -0800 (PST)\r\n返回路径: [电子邮件] protected]\r\n已收到:来自 dub0-omc1-s20.dub03.hotmail.com (dub0-omc1-s20.dub03.hotmail.com [157.55.0.220])\r\n ..... .
怎么可以我修好这个吗?
更新:在 Wodin 和 Avadhesh 的帮助下,我现在可以附加消息,但如何获取刚刚附加的消息的 UID?
I want to copy a message from one IMAP server to another IMAP server. I don't want to alter any of the message data. I'm using python imaplib.
This is the code I tried:
typ, data = connection1.uid('FETCH', uid, 'RFC822')
connection2.uid('APPEND', None, data[0][1])
But this raises an exception:
imaplib.error: UID command error: BAD ['"Delivered-To: [email protected]']
So the argument (data[0][1]) is not properly formatted I think.
The contents of data[0][1] look like this:
Delivered-To: [email protected]\r\nReceived: by 10.216.207.222 with SMTP id n27cs38120weo;\r\nFri, 12 Nov 2010 09:43:47 -0800 (PST)\r\nReceived: by 10.200.19.19 with SMTP id y19mr234526eba.52.12894526694;\r\nFri, 12 Nov 2010 09:43:46 -0800 (PST)\r\nReturn-Path: [email protected]\r\nReceived: from dub0-omc1-s20.dub03.hotmail.com (dub0-omc1-s20.dub03.hotmail.com [157.55.0.220])\r\n ......
How can I fix this?
Update: With the help of Wodin and Avadhesh I can append messages now, but how do I get the UID of a just appended message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决了!
首先复制消息
然后从复制的消息中获取唯一的消息ID,如下所示
然后使用消息ID在目标邮箱中查找新消息,如下所示
Solved it!
First copy the message with
Then fetch the unique message-id from the copied message like this
Then use the message-id to find the new message in the destination mailbox like this
您可以尝试以下代码:
如果看到电子邮件,则标志为“(\Seen)”,如果未看到电子邮件,则标志为“”。
You can try the follwing code:
where flags would be '(\Seen)' in case of seen email or '' in case of unseen email.
您是否尝试过:
RFC3501 显示了 UID 命令的语法如下:
即似乎没有“UID APPEND”命令。
Have you tried:
RFC3501 shows the syntax of the UID command as follows:
i.e. there appears not to be a "UID APPEND" command.