使用python保存.msg文件中的附件

时间:2017-08-09 14:48:44

标签: python python-2.7 win32com

我正在尝试下载一些驻留在文件夹中的<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html>` <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width"> <title>Prueba</title> <!-- Estilos --> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.12.2/dojo/resources/dojo.css" media="screen"> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.12.2/dijit/themes/claro/claro.css" media="screen"> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.12.2/dojox/layout/resources/FloatingPane.css" media="screen"> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.12.2/dojox/layout/resources/ResizeHandle.css" media="screen"> <!-- CSS --> <style> body, html {width:100%; height:100%; margin:0; padding:0; overflow:hidden;} </style> <!-- Libraries --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.12.2/dojo/dojo.js"> </script> <!-- Dojo --> <script> require([ "dijit/registry", "dijit/layout/BorderContainer", "dijit/layout/TabContainer", "dijit/layout/ContentPane", "dojox/layout/FloatingPane", "dojo/domReady!" ], function( registry, BorderContainer, TabContainer, ContentPane, FloatingPane) { //........................................................ var border = new BorderContainer({ design: "headline", style: "width: 100%; height: 100%; background-color: yellow;", design: "headline", liveSplitters: true, gutters: true }, "divBody"); //........................................................ border.addChild( new TabContainer({ region: "center", id: "tabs", tabPosition: "top" }) ); var tabs = registry.byId("tabs"); tabs.addChild( new ContentPane({ content: "content Tab 1", title: "Tab 1" }) ); tabs.addChild( new ContentPane({ content: "content Tab 2", title: "Tab 2" }) ); //........................................................ border.addChild( new ContentPane({ region: "top", id: "top", content: "HEADER" }) ); //........................................................ border.addChild( new ContentPane({ region: "left", id: "left", content: "LEFT", splitter: true, }) ); //........................................................ border.addChild( new ContentPane({ region: "bottom", id: "footer", content: "FOOTER", splitter: false }) ); //........................................................ border.startup(); //........................................................ var floating = new FloatingPane({ id: "floating", title: "A floating pane", resizable: true, dockable: true, style: "position:absolute; top:0; left:0;width:100px; height:100px;" }); floating.addChild( new ContentPane({ content: "FLOATING" }) ); floating.startup(); //........................................................ }); </script> </head> <body class="claro"> <div id="divBody"></div> </body> </html> 个文件的附件(不是专门用于Outlook)。

.msg

我一直收到此错误,这让我相信import win32com.client import os path = 'C:\\Users\\my_messages\\' files = [f for f in os.listdir(path) if '.msg' in f] print files for file in files: outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") msg = outlook.OpenSharedItem(os.path.join(path, file)) att=msg.Attachments for i in att: i.SaveAsFile(os.path.join(path, i.FileName)) 库存在问题。非常感谢任何帮助。

win32com

此行生成错误:

IOError: [Errno 2] No such file or directory: u'C:\\Python27\\lib\\site-packages\\win32com\\gen_py\\00062FFF-0000-0000-C000-000000000046x0x9x6\\ItemEvents.py.temp'

1 个答案:

答案 0 :(得分:0)

这里的问题是Python正在使用的库的问题,如下所示:

  • pypiwin32(更具体地说,调用outlook.OpenSharedItem)与全新安装的Python2.7一起使用
  • 在将库文件夹(site-packages\win32com)从正常工作安装复制到原始(错误)安装后,OP设法使其正常工作

需要进行更多调查以获得更清晰的答案,至少将库win32com 的工作版本复制到有问题的安装中为此问题提供了解决方法。