-
-
Save goors/df6bb706be9edfeb384e933ffb57f832 to your computer and use it in GitHub Desktop.
Forwarding emails to a Python script with procmail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:0Wc: | |
| env python mail_receiver.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From: [email protected] | |
To: [email protected] (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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procmail VERBOSE=on ~/.procmailrc < testemail.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment