Pages: 1
RSS
Invoking external tools and capture their output in email body, Feature Request: Macro for invoking external tool and capture its STDOUT
 
There is one feature I'm really missing in The Bat! — ie, the possibility of using macros to run an external process that returns some text to be inserted into the email contents.

With my previous client (Outlook Express, on XP) I would use that feature to include in my email template some random generated contents, using various apps. With Outlook Exp it required actually opening the whole email template via http, through localhost AppServ serving dynamic HTML pages (email template) disguised as HTML files (via .htaccess).

What I would like to achieve with The Bat! is a macro that instead of importing a text file can invoke an external binary file (with parameters and working folder, possibly) and then capture its STDOUT into the email — ie, in the macro's place. Maybe this macro should allow an optional parameter to specify enconding.

Currently there is only the cookies function, but I would like to use some more sofisticate applications to generate random text:

https://github.com/alvisespano/Polygen

... or applications like cowsay, etc.

Is there a way to currently achieve this with TB? Some macro I might have overlooked?

If not ... I would like to make a feature request for this.

I realize that there might be security concerns regarding this feature, so it might be disabled by default in TB Settings.

I had thought of creating this via custom plugins, but from a quick look at the Plugins documentation it didn't look like something that could be implemented in a friendly manner, like a macro would be. Definitely, a macro would be much friendlier for using this feature.

I was wondering, can users extend TB macros? is there a way to implement custom macros, via plugins or other means?
 
Quote
What I would like to achieve with The Bat! is a macro that instead of importing a text file can invoke an external binary file (with parameters and working folder, possibly) and then capture its STDOUT into the email

But if a program has STDOUT, its output can also be redirected into a text file. What benefit would your requested feature offer, over importing a text file?
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
 
Quote
Daniel van Rooijen wrote:
Quote
What I would like to achieve with The Bat! is a macro that instead of importing a text file can invoke an external binary file (with parameters and working folder, possibly) and then capture its STDOUT into the email
But if a program has STDOUT, its output can also be redirected into a text file. What benefit would your requested feature offer, over importing a text file?
The obvious benefits would be performance, since it would avoid to disk operations (writing the temp file, and then reading it), but as I explain below, there is also the problem of a two-steps operation which means the template has to wait for the file to be created before importing it.

But performance would'tn be really an issue here (it might be an argument sustaining the feature request, though), what I'm trying to understand is if it's currently possible to achieve my goal.

So, you're suggesting that I could edit a template to invoke the external app, so it creates the temporary file, and then import the created file, right? The whole idea is that the random text should be generated at the time the template is opened (writing a new email or replying to an email). The external tool would generate the random text by considering various factors, including the current date, etc. By "random text" I'm not talking of just some random phrase, or a quote picked from a list, but HTML format contents, which might include images, etc (basically, a banner created ad hoc, with some randomness to it).

I'm not sure how to achieve this via templates, what macro I'd be looking at? Is there a template macro to invoke an external binary application (or run a script)? I see only macros for including external text files, but nothing to invoke an app.

Also, I'm thinking that by using a temporary file and two-steps-operation I'll be facing the issue that the while the invoked external app is creating the temp file contents the template will be trying to read the temp file — ie: it might be reading an older version of the created file, or not find the file at all if it wasn't yet created. Unless the macro to invoke an external tool has the option of waiting for it to end execution, this might be a problem.
Edited: Tristano Ajmone - 17 March 2018 14:11:42
 
Leaving aside for a moment the usage scenario I've mentioned — ie, invoking an app that generates text —, a macro that would allow invoking external apps could have lot's of uses. The idea is that if templates had a macro to communicate with external apps it would provide a way to interface with other applications on a per mail basis.

I had looked at the issue in the past (but it was quite a while ago, so my memory isn't fresh) and I remember that I thought of implementing this via a plugin, but discovered that either it wasn't practical or possible because the API doesn't expose the required features to accomplish this (if I remember correctly, since it was quite a while ago that I looked into it). So it would have to be via a macro built into TB natively.

Ideally, such a macro would allow to invoke a binary app (or run an external script), set the working directory, and pass parameters — this would allow to send to the app info about the email using the template, such as the recipient, etc. Also, the macro should have an option to invoke the external app and wait for it to end (maybe with a time limit) and capture the exit code. Another macro option should allow capturing the app's STDOUT into a variable that can be then further manipulated.

This feature would open a wide range of new possibilities in the usage of email templates, and surely wouldn't create problems for those who don't need to use it.

It doesn't just regard the creation of text files to be imported in templates, but all sorts of interfacing with external apps.
 
You can already do all or most of what you want. It works by setting up a filter in the Sorting Office.

In the Actions field of the filter definition, you tell it to 'Run External Action'. In the Action's options, you can tell The Bat to wait for the external program to complete. Interestingly (I discovered only now), it seems you can also capture its STDOUT output..

The next Action that you define is, for example, that it must forward the message to a certain address. Here you can setup a template that uses the %PUT command to insert the file that your external app has generated earlier. Or, if you want to send a HTML message, maybe you can Attach it here as Message.html (I haven't tried).

If you want to manually control execution of the filter, you can define a hotkey for it in its options and specify 'Use this filter for manual re-filtering only'.

I hope this gets you started.
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
Pages: 1