.msg文件,outlook邮件的一种保存方式
def get_attachments(file_name, path_name): """ 获取.msg文件内的附件 :param file_name: .msg文件路径 :param path_name: 附件存放目录 :return: None """ outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") msg = outlook.OpenSharedItem(file_name) ''' print(msg.SenderName) print(msg.SenderEmailAddress) print(msg.SentOn) print(msg.To) print(msg.CC) print(msg.BCC) print(msg.Subject) print(msg.Body) ''' count_attachments = msg.Attachments.Count attachments = msg.Attachments if count_attachments > 0: # for item in range(count_attachments): # print(msg.Attachments.Item(item + 1).Filename) # 循环输出附件名 for att in attachments: att.SaveAsFile(os.path.join(path_name, att.FileName)) del outlook, msg # 释放资源