首页 > 解决方案 > 使用捕获的 .msg 文件内容创建新的 pdf

问题描述

print (msg.SenderName)
print (msg.SenderEmailAddress)
print (msg.SentOn)
print (msg.To)
print (msg.CC)
print (msg.BCC)
print (msg.Subject)
print (msg.Body)

我只是想采用上述内容,并将内容写入新创建的 .PDF 文件......因此,使用我在上面捕获的内容创建一个 .PDF 文件。

下面是完整的代码,我在其中打开.msg文件并提取它的内容......它正在打开.msg文件,并将内容正确输出到 Anaconda 提示窗口;只是还没有弄清楚如何使用 Python 将其推送到新创建的 .pdf 文件中。

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(r"C:\Users\path\path\test_msg.msg")

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
if count_attachments > 0:
    for item in range(count_attachments):
        print (msg.Attachments.Item)(item + 1).Filename

del outlook, msg

标签: pythonpdfpyfpdf

解决方案


推荐阅读