Jump to content


Photo

Pipe Emails To Python Script

python pipe email

  • Please log in to reply
3 replies to this topic

#1 topgeardavid

topgeardavid

    Rank I Member

  • Members
  • Pip
  • 34 posts
  • Gender:Male

Posted 19 May 2017 - 12:14 AM

How could I set up a forwarding address that pipes to a Python script? What path should the script be at?



#2 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 12,403 posts
  • Gender:Not Telling

Posted 19 May 2017 - 02:58 AM

Good question. You can put the script anywhere in your account, but I would recommend /home/dr/email.py because that's not accessible through a browser for the extra security.
  • First go to https://tommy.helioh...agefilters.html
  • Pick the email address that you want to forward to the script and click manage filters next to it.
  • Click create new filter.
  • Name is "Pipe to Python" or whatever.
  • Set up your rules if you only want certain emails to be piped or all of them, etc.
  • In the actions dropdown box select pipe to a program
  • Enter the path to your python script with a pipe character first, such as |/home/dr/email.py
  • Click create
Then as far as the python script goes you'll need the python shebang for the version you want to use first, and then the email will come to the script along stdin so you can process the text as you would any other stdin input.

#3 topgeardavid

topgeardavid

    Rank I Member

  • Members
  • Pip
  • 34 posts
  • Gender:Male

Posted 19 May 2017 - 03:24 AM

Awesome, thanks! This works with filters, but when I try this with a forwarding address, I keep getting this error:

Could not exec '/home/dr/email_reply.py'

Can I only pipe to Python with filters?


Could not exec '/home/dr/email_reply.py'


#4 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 12,403 posts
  • Gender:Not Telling

Posted 19 May 2017 - 04:25 AM

It looks like you forgot the pipe character | That's very important. It should look like
|/home/dr/email_reply.py
Yes, this will only work with filters. Forwarding just takes the email changes the to: field and sends it back through the email system. Filter is what processes the email.





Also tagged with one or more of these keywords: python, pipe, email

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users