첨부 파일이있는 메일 전달에 문제가 있습니다. 누구든지 올바른 방향으로 나를 가리킬 수 있습니까? 나는 그것이 Fetch 문에 있다고 추측하고 있지만 확신 할 수는 없다.Python - 첨부 파일이 포함 된 IMAP 전자 메일 (imaplib, smtplib)
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()
[IMAPClient] (http://imapclient.freshfoo.com/)를 확인 (imaplib 사용에 대한 많은 좌절감을 완화하기) 할 수 있습니다. – Acorn