Sending Mail to a Script

I'm trying to move everything from Webfaction to Linode, so trying to recreate some of the functionality I had there.

I have a simple page that is created from an email newsletter by a python script. It's a very simple process that Webfaction has available using mail2script. https://docs.webfaction.com/user-guide/email.html#sending-mail-to-a-script

What would I need to recreate that on Linode?

Do I actually need a mail server running?

1) email is received
2) send it to script (existing script does the rest)

Also found this script that is a replacement for WF mail2script that might be able to be adapted. https://gist.github.com/defulmere/1159755

1 Reply

Yes, you need a mail server.

Does all your incoming mail get sent to the script? If so, that's easy (assuming you're using postfix(1)):

https://thecodingmachine.io/triggering-a-php-script-when-your-postfix-server-receives-a-mail

The script doesn't have to be a PHP script…just any script that reads from STDIN (I've used scripts written in both ruby & perl for example).

If you want to mail to SOME email addresses to be processed by the script, you're probably going to need a local-delivery agent (LDA) that supports sieve (dovecot(1) and dovecot/pigeonhole -- https://pigeonhole.dovecot.org -- fill the bill nicely here). However, setting all this up is not for the faint of heart.

If you elect to use dovecot/pigeonhole, you need to make sure the pigeonhole-specific enhancement vnd.dovecot.pipe is enabled. This allows you to use sieve to pipe incoming mail to an external program. Just in case you haven't figured it out, hooking into dovecot(1) will only allow you to process incoming mail.

In any case, the external script needs to be bullet-proof! None of postfix(1), dovecot(1) and dovecot/pigeonhole are very tolerant of script failures other than to generate an error in the log and continue on (the incoming message may not be saved unless you take extraordinary measures to do so).

On the bright side, once you have a setup that works reliably, you prob won't have to change it much (if at all). Testing all this is a perfect application for a nanode… You can configure postfix to accept mail from only a certain domain or set of IP addresses and to not send mail at all (or only send mail to certain domains or IP addresses).

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct