Read email from a system pipe into python

2558 0

#!/usr/local/bin/python

import sys
import email

full_msg = “”
for line in sys.stdin
full_msg += line

msg = email.message_from_string(full_msg)

to = msg[‘to’]
fromwho = msg[‘from’]
subject = msg[‘subject’]

#make an emty variable for email body
body = “”

#if the message contains attaachments find the body attachment
#if not find the entire emial body
if msg.is_multipart():
for payload in msg.get_payload():
# if payload.is_multipart(): …
body = payload.get_payload()
else:
body = msg.get_payload()

Facebooktwitterredditpinterestlinkedinmail

Related Post

Pi Camera Resolution Fix

Posted by - October 24, 2015 0
[crayon-6629e1c915bd7333870526/] Keep Reading : Wire camera to pi while loop Hello World Remote ssh connect from iPad P.C. and laptop…

google map link

Posted by - October 18, 2015 0
http://www.google.com/maps/place/40.625027,-73.957774/@40.625027,-73.957774,17z Change RED part to current GPS in Python   http://maps.google.com/maps?q=40.37494164,-73.57485968   Keep Reading : GPS AT Commands GPS RESPONSE…

Hello World

Posted by - August 15, 2015 0
We use python to write all of our scripts. On our raspberry pi every python script starts with a shebang…

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.