Quantitative finance collector
C++ Matlab VBA/Excel Java Mathematica R/Splus Net Code Site Other
Jul 6

Send SMS in Matlab

Posted by abiao at 13:17 | Code » Matlab | Comments(0) | Reads(17999)
Ros is a colleague of mine in the same office, his main research is empirical analysis of different option pricing models, and as a result, he often use several computers on different desks to run his matlab codes, which is time-consuming and not rare to last 2 or 3 days. So he has to come back office frequently to check which computer has finished the task. It sounds boring, why not write a small script to send SMS message to you automatically when your matlab stops running?

Send Text Message to Cell Phone is such a great file I found recently, bascially what it does is to send email via sendmail function of Matlab from your gmail box to your cell phone carrier, and then your cell phone carrier forwards the email to you as a text message.

However, it works for US based cell phones only, I have tried on my UK T-mobile phone and it seems UK T-mobile doesn't support such a mail to SMS service (correct me if I am wrong).

Fortunately, I came across SMS service website which allows people to send up to 3 free email to SMS per day, it should be enough for our use in Matlab. Add the following line in the switch case after line 55
case 'uk';    emailto = strcat(number,'@x-onsms.com');

that's it, the email will be delivered as an SMS to your mobile. Do let me know if you are aware of a better alternative.

So what you need to do is to put the function send_text_message at the end of your file, it will then send you a message automatically, for example
send_text_message('079-123-456','UK', 'Desk 12 Calculation Done','Now you can shut down the computer')

What else can it be used? stock price alert? profit threshold alarm? you name it.

Possible error

Depends on your Matlab version and firewall setting, you may notice the following errors:
1, ??? Error using ==> sendmail
530 5.7.0 Must issue a STARTTLS command first

This could happen for MATLAB 7.1 (R14SP3) and before, you may have to upgrade your version.

2, Could not connect to SMTP host: smtp.gmail.com, port: 25;
Connection timed out: connect

This is due to your firewall or anti-virus software setting. you are not allowed to send email from port 25. What you shall do is too add an exception and let your computer know this action is safe. For instance, I have McAfee, to add an exception, open its control console -> double click access protection -> anti-virus standard protection -> prevent mass mailing worms from sending mails -> Edit
Open in new window

add Matlab.exe as a process to be excluded, save it, done.
Open in new window

Ros, you don't have to check computers one by one. Sounds useful? download the file at http://www.mathworks.com/matlabcentral/fileexchange/16649, don't forget to change the email address and password at the beginning of the file.

Tags: ,
Add a comment
Enable HTML
Enable UBB
Enable Emots
Nickname   Password   Optional
Site URI   Email   [Register]