email automation

Brian J. Oney brian.j.oney at googlemail.com
Tue Oct 23 07:58:27 EDT 2018


On Tue, 2018-10-23 at 10:31 +0100, Ali Rıza KELEŞ wrote:
> On Tue, 23 Oct 2018 at 09:07, Thomas Jollans <tjol at tjol.eu> wrote:
> > > After some basic research I have a few options:
> > > 
> > >      1. Grapple with OpenEMM (interesting software, has python library, still alive and kicking, a bit overkill for my use-case);
> > >      2. build on the examples in 'Automate the boring stuff';
>> > From briefly skimming the relevant section, it looks like this gives
> > some examples with smtplib and imaplib. That sounds like a good place to
> > start!
>> > If you happen to have a server (VPS, Raspberry Pi, PC, whatever) running
> > a full MTA that you can forward your emails to, you could feed the
> > relevant messages to your script directly with the help of procmail,
> > rather than polling an IMAP server.
> 
> +1
> 
> I experienced procmail and worked like a charm for me, in a case like
> yours. My script was parsing emails to grab some URIs of binary
> objects and queue them to be processed later.
> 
> You can easily trigger a python script and do whatever you need in
> that script. If it is a long term process, you should just parse email
> and use queues for the rest.
> 

Thank you for the insights. The developer of procmail says to avoid it, as the
last update was in 2001. Supposedly there are also some security concerns.
The mail server does some pretty good filtering already.

I made the mistake of being vague about the problem. Let me specify.

  - General Problem: too many emails to answer with due care
    - Technical Problem 1: can't be run on mail server.
    - Technical Problem 2: answers needed in 2 and possibly 4 languages.
    - Future Problem 3: don't have resources to maintain the solution forever
    - Future Problem 4: software may be running in many different countries
      with different languages and legal frameworks.
  - Goal: lighten the load 
    - Potential: many emails pose questions to information already on the
      website.
  - Potential solution: automate personalized replies with relevant
    information.

Nonetheless, barring a tip to an existing solution, I will be rolling my own.

Off the top of my head, I image the setup being eerily similar to a flask
website. I would rely on smtplib, imaplib, nltk, pyzmail, and jinja2.

Draft Algorithm:
  1. read mail
  2. tokenize body's contents
  3. apply logic to determine answer
  4. render appropriate answer template
  5. send email
  6. refile email

maildog/
  app.py
  answer_logic/
    english.csv
    german.csv
    french.csv
  maildog/
    __init__.py
    send_mail.py
    read_mail.py
    refile_mail.py
    decide_answer.py
  templates/
    base.html
    base.txt
    info.html
    info.txt
    schedule.html
    schedule.txt
  tests/
    test_answer_common_email.py
    test_explain_upcoming_schedule.py
    test_read_email.py


Somehow I think someone smarter already solved this niche case. A part of me
wants to delve into OpenEMM. The rest wants to write code.

Now that it seems that I will be writing this. What is the recommended way to
set up a timer. I know 2 system options, systemd timers and cron jobs. I
prefer the former for the handy logging options. What about a python solution?
What would the advantage of a python queue be over a systemd timer? I guess
that's an apples an oranges comparison. In my case I most likely would have a
raspberry pi running a python script to read and possibly answer any emails.

Thanks again for the tips.

Regards,
Brian




More information about the Python-list mailing list