Solved Run script on new email
-
Can I possibly trigger a script to run when email arrives in a Cloudron inbox?
-
@yusf what kind of script ? sieve essentially does this, can you create a mail rule?
-
@girish I don’t know as I’ve zero experience with Sieve. I want to curl with POST to an external server. Ideally containing the email contents but at least its sender and subject data.
-
In the old days of mail in unix terminals, you could do that with a .forward file which could run shell scripts.
What's the bigger purpose?
Since all email goes through spam filtering, there's an opportunity to hook into what you need there too.
-
@yusf generally, the 'robust' way to do this is to implement this, is in the app and not in the mail server. This takes care of situations where the app is down, app is busy etc. For example, chatwoot, freescout, gitlab all have built-in support for IMAP.
-
@yusf why not run a script in cron (on the cloudron server) that monitors the mailbox via imap?
-
@murgero Sounds excellent, show me how
-
@yusf Sadly I am not sure on specifics, but this answer on stackexchange really goes into detail on options you can do in bash: https://unix.stackexchange.com/a/537196
-
@yusf depending what you want to do exactly, 2 excellent utilities I have used previously are :
- imapfilter (https://github.com/lefcha/imapfilter)
- offlineimap (http://www.offlineimap.org/)
You will probably need to write the meat of your script in bash or php or whatever, but this will get you access to raw email.
And can be run by cron and targeted to mail in certain folders.
-
Thanks guys, I check out those resources provided
-
girish
-
girish