0

ヘッダーとフッターを添付せずに Python を使用して電子メールの本文を取得することは可能ですか? 私の現在のコードは

import imaplib
username = "username"
password = "password"
imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
imap_server.login(username, password)
imap_server.select('INBOX')

def get_emails(email_ids):
    """
    Takes in an array of email id's as input eg: ['1','7']
    Returns an array of html strings corresponding to the given email id's"""
    data = []
    for e_id in email_ids:
        status, response = imap_server.fetch(e_id, '(UID BODY[TEXT])')
        data.append(response[0][1])
    return data

出力 HTML 文字列は次のようなものです。

--0016e6d9770b63df7104cebab205 Content-Type: text/plain; charset=ISO-8859-1
This is some html code

--0016e6d9770b63df7104cebab205 Content-Type: text/html; charset=ISO-8859-1 <html>
    <body>
<p>This is some html code</p>
</body>
</html>
--0016e6d9770b63df7104cebab205--

ヘッダーなしで HTML だけを使用することは可能ですか? 例:見たい

<html>
    <body>
<p>This is some html code</p>
</body>
</html>

出力として。ありがとう!

4

1 に答える 1

0

email.parserなどの Python の電子メール サポート クラスを使用して、受信したメッセージを解析し、適切な MIME 部分を取得する必要があります。または、IMAP の BODYSTRUCTURE 応答を使用して、それを使用して、ダウンロードする電子メールの部分を正確に把握することもできます。

于 2012-12-05T19:27:30.697 に答える