File Exchange

image thumbnail


version (2.13 KB) by Benjamin Kraus
Notify you via email or text message when your functions finish or crash.


Updated 16 Sep 2010

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

notifier - Notifies you via email when a function finishes.

varargout = notifier(recipients, fh, varargin)

notifier is a wrapper for a sub function. It takes as input a list of recipients, a function handle, and arguments for the sub function. It then calls the sub function, passing in all the arguments, and notifies the recipients via email when the sub function completes. In the event of an error, the text of the error message is sent to the recipients via email. This is designed for long running functions, so you can leave the computer and be notified when to come back. This function uses sendmail to send notices, so make sure that sendmail is working properly before attempting to use this function. Sendmail accepts email addreses, but if your phone/carrier supports this feature, you can often use specially fomatted email addresses to send TXT messages to your mobile phone. For example, for Verizon Wireless, you can use the email address <phonenumber>, such as

recipients - E-mail addresses to notify. Passed directly to sendmail,
so see the documentation for sendmail for formatting.
fh - Function handle for the sub function to run.
varargin - Input arguments passed directly to the sub function.

varargout - Output from the sub funtion is passed directly as output
from this function.

Without notifier:
output = myfunc(arg1, arg2)
With notifier:
output = notifier('', @myfunc, arg1, arg2)

Cite As

Benjamin Kraus (2021). Notifier (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

Kelly Kearney

Very nice function. I found that my text messages were often truncated when using this with anonymous functions with a large number of input parameters, so I added the following few lines to allow a function nickname to be used in the subject line of emails/texts:

if iscell(fh)
fhname = fh{2}; % nickname
fh = fh{1}; % function handle
fhname = func2str(fh);


Ah, good thinking. I understand and like the rationale.

Benjamin Kraus

@Jiro: The first call to SENDMAIL is intended to fail and stop execution if SENDMAIL is not configured properly. This is a sanity check so that you find out immediately that SENDMAIL isn't working correctly, rather than four hours later when your script ended after an hour and you have no idea why you were never notified. If you start the script, you will either notice immediately that SENDMAIL returned an error, or you will never get the "Start" notification, and know something is amiss.


Oops, clicked on submit before leaving a comment.

Very nice idea and well-coded (and documented). One suggestion. You put a try-catch around the second and third call to SENDMAIL, but not the first. I suggest making a subfunction for the call to SENDMAIL that includes the try-catch, and call that subfunction in the three locations.


MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!