Read email from a system pipe into python

2942 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

Raspi-config

Posted by - August 15, 2015 0
First you will need to open terminal. Terminal is located at the top of your raspberry pi screen. Terminal is…

Identify USB device and discover its name and port

Posted by - October 17, 2015 0
Download latest PyUSB from : http://sourceforge.net/projects/pyusb/files/PyUSB%201.0/1.0.0-beta-2/pyusb-1.0.0b2.tar.gz/download Place file “pyusb-1.0.0b2.tar.gz” on your desktop gunzip <pyusb-1.0.0b2.tar.gz |tar xvfp - cd pyusb-1.0.0b2 sudo ./setup.py…

Add Clock Via i2c

Posted by - October 24, 2015 0
Prepare i2c added real time clock driver to raspian Add time variable to picture display Solder pins to clock module…

Pi Camera Resolution Fix

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

python to send a SMS message

Posted by - October 18, 2015 0
[crayon-67504886049a3210349394/] Keep Reading : Serial Communication with SMS Modem (FONA) GPS RESPONSE CODE ORDER Serial Commands used by our Satellite…

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.