我无法使用附件转发邮件。谁能指出我正确的方向?我猜这是在Fetch语句中,但我不确定。
import sys
import uuid
import re
import smtplib
import email
address = ''
username = ''
password = ''
def checkMail():
M = imaplib.IMAP4_SSL(address)
M.login(username, password)
M.select("INBOX", readonly=True)
typ, data = M.search(None, 'Unseen')
messageCount = len(data[0].split())
print('messageCount: %', messageCount)
if messageCount > 0:
for num in data[0].split():
typ, data = M.fetch(num, '(BODY[TEXT])')
foundAt = data[0][1].find('Content-Type: application')
if(foundAt > 0):
print('attachmentfound')
sendMail(data[0][1])
M.close()
M.logout()
def sendMail(raw_message):
toAddress = ''
fromAddress = ''
LOGIN = ''
PASSWORD = ''
server = smtplib.SMTP('', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(LOGIN, PASSWORD)
server.sendmail(fromAddress, toAddress, raw_message)
server.quit()
def main():
checkMail()
main()
答案 0 :(得分:0)
如果你想使用imaplib,为什么不直接获取整个消息(RFC822)?看到这个类似的问题:
答案 1 :(得分:0)
这是获取...为(BODY [])添加一个获取技巧。