Is possible to run a script when I press the button Update?

I would like to run a script in any language, Python for example, to execute some tasks that I need to refresh emails.

This question is related to this other question where I state that I need to press the “Refresh” button in order to fetch new emails from my external webmail client.

Is there a builtin way to do this? If not, I think I would have to do it periodically using cron or the task scheduler.