개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.05.01 22:26

imap_fetchstructure 함수 사용 시 오류 발생

목록
  • Go매니아 22시간 전 2025.05.01 22:26 새글
  • 6
    1
선생님, imap_fetchstructure 함수를 사용하여 메일의 구조를 가져올 때, 메일의 첨부 파일이 여러 개 있는 경우에 발생하는 오류에 대해 질문을 드려 죄송합니다.

imap_fetchstructure 함수를 사용하여 메일의 구조를 가져올 때, 메일의 첨부 파일이 여러 개 있는 경우에 발생하는 오류에 대해 질문을 드려 죄송합니다.

첨부 파일이 여러 개 있는 메일을 가져올 때, imap_fetchstructure 함수는 첨부 파일의 구조를 모두 가져오는지 궁금합니다.

첨부 파일이 여러 개 있는 메일을 가져올 때, imap_fetchstructure 함수를 사용하여 구조를 가져올 수 있는 방법이 있을까요?

    댓글목록

    profile_image
    나우호스팅  22시간 전



    imap_fetchstructure 함수는 메일의 구조를 가져올 때, 첨부 파일의 구조를 모두 가져오지 않는 것으로 보입니다.

    이러한 문제를 해결하기 위해 imap_fetchbody 함수를 사용할 수 있습니다. imap_fetchbody 함수는 메일의 첨부 파일을 가져올 때, 첨부 파일의 구조를 모두 가져올 수 있습니다.

    imap_fetchstructure 함수를 사용할 때, 첨부 파일이 여러 개 있는 메일을 가져올 때, 다음과 같이 사용할 수 있습니다.

    #hostingforum.kr
    python
    
    import imaplib
    
    import email
    
    
    
    # imaplib를 사용하여 메일 서버에 접속합니다.
    
    mail = imaplib.IMAP4_SSL('imap.gmail.com')
    
    mail.login('your_email@gmail.com', 'your_password')
    
    mail.select('inbox')
    
    
    
    # 메일을 가져옵니다.
    
    status, messages = mail.search(None, 'ALL')
    
    
    
    # 메일의 구조를 가져옵니다.
    
    for num in messages[0].split():
    
        status, data = mail.fetch(num, '(RFC822)')
    
        raw_email = data[0][1]
    
        email_message = email.message_from_bytes(raw_email)
    
    
    
        # 첨부 파일의 구조를 가져옵니다.
    
        for part in email_message.walk():
    
            if part.get_content_maintype() == 'multipart':
    
                continue
    
            if part.get('Content-Disposition') is None:
    
                continue
    
            filename = part.get_filename()
    
            if filename:
    
                print(f'첨부 파일 이름: {filename}')
    
                print(f'첨부 파일 크기: {len(part.get_payload())}')
    
    


    이러한 코드를 사용하면, 첨부 파일이 여러 개 있는 메일을 가져올 때, 첨부 파일의 구조를 모두 가져올 수 있습니다.

    2025-05-01 22:27

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 16,067건 / 2 페이지

검색

게시물 검색