-
-
Save alvinlai/3237722 to your computer and use it in GitHub Desktop.
receiving (postfix) emails via (rails) http; using file upload (-F) for less verbose Rails log (otherwise use --data-urlencode)
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
#!/bin/bash | |
MAILFILE=/tmp/mail.$$ | |
CURLFILE=/tmp/mail.$$.curl | |
cat > $MAILFILE | |
curl -i -F message=@$MAILFILE "http://localhost/incoming_messages" > $CURLFILE | |
if grep 'HTTP/1.1 204 No Content' $CURLFILE | |
then | |
rm -f $CURLFILE $MAILFILE | |
fi |
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
class IncomingMessagesController < ApplicationController | |
def create | |
raw = params[:message].respond_to?(:read) && params[:message].read || params[:message] | |
mail = Mail.new(raw) | |
# do stuff | |
head(:no_content) # bash script will detect 204 and rm -rf tmp files | |
end | |
end |
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
mailbox_command = /somewhere/diy.cloudmailin.bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment