python: extract and download an image from the body of the email <p>I am trying to read the content of the email. If an email contains an image in the <strong>BODY</strong> part I need to extract and save it in the local Here is the code for getting the body content</p> <pre><code>def get_body(id): res, mail_data = connection.fetch(id, '(RFC822)') raw_email=mail_data[0][1] email_message_instance = email.message_from_string(raw_email) whole_body = '' for part in email_message_instance.walk(): if part.get_content_type() == "text/plain": # ignore attachments/html body = part.get_payload(decode=True) whole_body += body + ' ' else: continue return whole_body </code></pre>