Outlook COM:如何从.msg文件创建MailItem [英] Outlook COM: how to create a MailItem from a .msg file
问题描述
大家好,
我一直在编写一些代码来将一些数据移入和移出Outlook(2003
+ Exchange 2003)。我在我们的文件服务器上有一些电子邮件.msg文件,而我似乎无法让他们回到我需要的Outlook对象,即一个MailItem。
我曾尝试使用App.CopyFile()(临时)将文件放在OL
文件夹中。但问题是,这会返回一个DocumentItem,而不是一个MailItem。
有什么方法可以将这个DItem投射到一个MItem中吗?显然,OL
将其视为任何一般文件 - 其中,btw也在视图中显示;它
有另一个图标,你必须打开它才能查看它。或者也许还有另外一种打开它的方式。我真的只需要内存中的对象。有什么想法吗?
TIA,
g
Hi all,
I''ve been writing some code to move some data into and out of Outlook (2003
+ Exchange 2003). I have some email .msg files on our file server, and I
can''t seem to get them back into the Outlook object I need, ie a MailItem.
I''ve tried to use App.CopyFile() to (temporarily) put the file in an OL
folder. Problem is, however, this returns a DocumentItem and not a MailItem.
Is there any way I could ''cast'' this DItem into a MItem? Apparently, OL
treats it as any general document - which, btw, shows in the view, too; it
has another icon and you have to open it to view it). Or maybe there''s
another way to open it; I really only need the object in memory. Any ideas?
TIA,
g
推荐答案
7月4日/ 05,Guy Lateur< gu ******** @ bb.be>写道:
On 7/4/05, Guy Lateur <gu********@b-b.be> wrote:
我一直在编写一些代码来将一些数据移入和移出Outlook(2003
+ Exchange 2003)。我的文件服务器上有一些电子邮件.msg文件,我似乎无法将它们放回到我需要的Outlook对象中,即一个MailItem ..
我试过用App.CopyFile()将(暂时)将文件放在OL
文件夹中。但问题是,这会返回一个DocumentItem,而不是一个MailItem。
我有什么方法可以将这个DItem投射到一个MItem中吗?显然,OL
将其视为任何一般文件 - 顺便说一下,在视图中也是如此;它有另一个图标,你必须打开它才能查看它。或者也许有另一种打开它的方法;我真的只需要内存中的对象。有什么想法吗?
I''ve been writing some code to move some data into and out of Outlook (2003
+ Exchange 2003). I have some email .msg files on our file server, and I
can''t seem to get them back into the Outlook object I need, ie a MailItem..
I''ve tried to use App.CopyFile() to (temporarily) put the file in an OL
folder. Problem is, however, this returns a DocumentItem and not a MailItem.
Is there any way I could ''cast'' this DItem into a MItem? Apparently, OL
treats it as any general document - which, btw, shows in the view, too; it
has another icon and you have to open it to view it). Or maybe there''s
another way to open it; I really only need the object in memory. Any ideas?
好吧,我对Outlook的COM接口一无所知,所以我不会这么做b $ b知道这是否有效,但你可以尝试win32com.client.CastTo()。
类似于:
my_MItem = win32com.client.CastTo(my_DItem) ,''MItem'')
-
干杯,
Simon B,
si *** @ brunningonline.net ,
http://www.brunningonline.net/simon/blog/
感谢小费,西蒙,但不幸的是它不起作用;它说
接口名称''MailItem''与对象不出现在同一个库中
''< win32com.gen_py.Microsoft Outlook 11.0对象库._DocumentItem
实例在0x29912600>"
我还能尝试其他什么吗?
干杯,
g
" Simon Brunning" < SI ************ @ gmail.com> schreef在bericht
新闻:ma ************************************ *** @ pyt hon.org ...
好吧,我对Outlook的COM接口一无所知,所以我不知道
知道这是否有效,但你可以尝试win32com.client.CastTo()。
类似于:
my_MItem = win32com.client .CastTo(my_DItem,''MItem'')
-
干杯,
Simon B,
si***@brunningonline.net ,
http://www.brunningonline.net/simon/blog/
Thanks for the tip, Simon, but unfortunately it doesn''t work; it says "The
interface name ''MailItem'' does not appear in the same library as object
''<win32com.gen_py.Microsoft Outlook 11.0 Object Library._DocumentItem
instance at 0x29912600>"
Anything else I could try?
Cheers,
g
"Simon Brunning" <si************@gmail.com> schreef in bericht
news:ma***************************************@pyt hon.org...
Well, I don''t know anything about Outlook''s COM interface, so I don''t
know if this will work, but you might try win32com.client.CastTo().
Something like:
my_MItem = win32com.client.CastTo(my_DItem, ''MItem'')
--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
On 7 / 4/05,Guy Lateur< gu ******** @ bb.be>写道:
On 7/4/05, Guy Lateur <gu********@b-b.be> wrote:
我还能尝试其他什么?
Anything else I could try?
横向思维?
===未经测试===
导入imaplib,time,sys
f = open(msg_file)
r = f.readlines()
f.close()
msg1 =''''。join(r)
server =' 'my.exchangeserver.com''#或IP地址
user =''user''
pw =''pw''
M = imaplib.IMAP4(服务器)
M.sock.settimeout(120)
M.login(用户,pw)[1 ] [0]
M.select()
M.append(''INBOX'',None,time.time(),msg1)#Inbox或其他文件夹姓名
打印MESSAGE成功保存
#M.close()不要使用关闭,删除/清除物品
M .logout()[1] [0]
Lateral thinking ?
=== untested ===
import imaplib, time, sys
f = open(msg_file)
r = f.readlines()
f.close()
msg1 = ''''.join(r)
server = ''my.exchangeserver.com'' # or IP address
user = ''user''
pw = ''pw''
M = imaplib.IMAP4(server)
M.sock.settimeout(120)
M.login(user,pw)[1][0]
M.select()
M.append(''INBOX'',None ,time.time() , msg1) # Inbox or other folder name
print "MESSAGE successfully saved"
#M.close() Don''t use close, deletes/purges items
M.logout()[1][0]
这篇关于Outlook COM:如何从.msg文件创建MailItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!