Skip to content

Instantly share code, notes, and snippets.

@leifdenby
Last active March 23, 2024 03:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save leifdenby/a85a487bf537ac6ae045 to your computer and use it in GitHub Desktop.
Save leifdenby/a85a487bf537ac6ae045 to your computer and use it in GitHub Desktop.
Forwarding emails to a Python script with procmail
:0Wc:
| env python mail_receiver.py
import sys
import email
full_msg = sys.stdin.read()
msg = email.message_from_string(full_msg)
to = msg['to']
subject = msg['subject']
body = msg['body']
with open('%s-%s.txt' % (msg['from'], subject), 'w') as f:
f.write(full_msg)
From: me@example.com
To: me@example.com (self test)
X-info: I'm just testing
BODY OF MESSAGE SEPARATED BY EMPTY LINE
txt txt txt txt txt txt txt txt txt txt
procmail VERBOSE=on ~/.procmailrc < testemail.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment