Read email from a system pipe into python

2933 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

Phase One

Posted by - August 15, 2015 2
“Phase One” is where we learned basic raspberry pi use. we started with the unboxing of our model 2 B raspberry…

LED Blinking

Posted by - August 15, 2015 0
You will need the following things: Raspberry pi configured (see previos lessons) 5 Volt LED bulb(s) 2 jumper wires m/f…

while loop

Posted by - October 18, 2015 0
[crayon-673ef647977c5515537929/] Keep Reading : Pi Camera Resolution Fix Hello World LED Blinking Wire camera to pi

Turn string into array with split

Posted by - October 18, 2015 0
textWithCommas = “bee,apple,pear,dog,carrot,robot” wordList = textWithCommas.split(“,”) print “the second item is : ” + textWithCommas[1] Keep Reading : Identify USB…

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.