Using RPC by email?

Can someone tell me how they did it in one form or another, be it XML-RPC, SOAP, ordering, etc. Do not worry too much about the package format.

I am interested in doing some kind of RPC by email, setting up a program to receive commands by email from another application or even from users in the subscription list. Basically, the idea is that you give someone an email address and then send messages to active teams, and the response is returned by email. A good example of where I will take this, maybe a chess program, where time does not matter, but delivery is everything, and the sequential order of moves is given.

I would be most interested in the experience of others, especially with the nature of the email and any individual behavior that I should be aware of.

I have a lot of RPC experience in message queuing and asynchronous delivery, but I would like to come up with a solution in which I transfer messages to hotmail or gmail, freeing up my servers and the headache of asynchronous intercoms.

+3
source share
2 answers

You can use fetchmail as follows:

#!/bin/bash
while sleep 1
do
    fetchmail --idle --mda python program_that_accepts_email_with_headers_on_stdin.py
done

, http, - . , , . ~/.fetchmailrc( man fetchmail , ). - , , , . , , ( ).

, , ( , 3 , ).

: (--idle) IMAP. - , 10 1. 1 , ( , , - ) , , 1 . :) , 1 . , sleep 1 true.

+2

Google AppEngine Python. .

app.yaml , , :

application: appname
version: 1
runtime: python
api_version: 1

handlers:
- url: /_ah/mail/.+
  script: mail.py
  login: admin

inbound_services:
- mail

mail.py - :

#!/usr/bin/env python

import rfc822
import logging

from google.appengine.ext import db
from google.appengine.ext import webapp 
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler 
from google.appengine.ext.webapp.util import run_wsgi_app

class LogSenderHandler(InboundMailHandler):
    def receive(self, message):
        service_name, service_email = rfc822.parseaddr(message.to)
        service_request = service_email.split('@').pop(0)
        sender_name, sender_email = rfc822.parseaddr(message.sender)

        logging.info('Service `%s` activated by `%s`.' % (service_request, sender_email))

if __name__ == '__main__':
    application = webapp.WSGIApplication(
        [LogSenderHandler.mapping()])
    run_wsgi_app(application)

, , servicename@appname.appspotmail.com. !

+2

Source: https://habr.com/ru/post/1772423/


All Articles