0
我已经能够弄清楚如何在电子邮件中获取附件的名称。之后我就被卡住了。我不知道该做什么后,我已经尝试使用os.path.join
,它只是给我想下载文件夹的路径,并与文件名连接。请提出建议。谢谢。在电子邮件中复制附件。
m = imaplib.IMAP4_SSL('outlook.office365.com',993)
m.login("UN", "PW")
m.select("Inbox")
typ, msgs = mail.search(None, '(SUBJECT "qwerty")')
msgs = msgs[0].split()
for emailid in msgs:
resp, data = mail.fetch(emailid, "(RFC822)")
email_body = data[0][1]
m = email.message_from_bytes(email_body)
if m.get_content_maintype() != 'multipart':
continue
for part in m.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
filename = part.get_filename()
print(filename)
采取在这个问题上的样子: [GET-的Gmail邮箱,附件文件名,而无需的下载,它(http://stackoverflow.com/问题/ 13663672/get-the-gmail-attachment-filename-without-downloading-it) –
@MiguelFebres没问题,所以它将文件获取到python文件所在的文件夹。你能告诉我如何将文件传送到特定的文件夹。如果你可以发表你的答案作为答案,我可以接受它作为正确的答案。 你是男人! :D非常感谢! – qwerty