On 3/22/22 11:27, João Silva wrote:
> 
> On 22/03/2022 14:57, Edward Sandberg wrote:
>> You could use inotify to monitor a directory and trigger a script to 
>> send the mail.
>>
>> Here is a very simple example content of such an email file, but they 
>> get much more complex.
>>
>> To: f...@bar.com
>> From: b...@foo.com
>> Subject: example email
>>
>> Hello World!
>>
>> If the files are valid email files with headers you could just pipe 
>> them to sendmail.
>>
>> If the files are not valid emails with headers then you could send 
>> them as attachments. Something like the python module envelope would 
>> be a simple way to do this: https://pypi.org/project/envelope/
> 
> The following code (function) takes a bytesIO object and attaches it to 
> an email.
> 
> A warning about inotify and python, if the rate of writing new files to 
> a directory is too high python may not keep up to it there are events 
> that may be "lost". I have found it the hard way.

This is not specific to Python.  It’s a general limitation of the
inotify interface, and is necessary to avoid a trivial denial of
service by being slow to consume events.  Inotify does tell you when
events have been lost, though, which allows you to resynchronize.
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

Attachment: OpenPGP_0xB288B55FFF9C22C1.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to