No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Send Text Message to Cell Phone

3.5 | 26 ratings Rate this file 57 Downloads (last 30 days) File Size: 3.55 KB File ID: #16649 Version: 1.0

Send Text Message to Cell Phone


Ke Feng (view profile)


29 Sep 2007 (Updated )

Send text message to cell phone or other mobile devices

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

Use this function to send text message to cell phone or other mobile devices. Currently, it works for US based cell phones only.

I found it useful for people who does time-consuming computations constantly. My lab mate often called me in and asked me to check his computer to see if his computations are over. I made this small function for him so he get notified on his cell phone when the computation is done, and he loves it. I think others might like it as well.


This file inspired Txt Msg Create and Send Messages To Emails And/Or Cell Phones.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (44)
29 Jan 2017 Johan Portström

06 May 2016 Benjamin Neuner

I tried changing my gmail security but it still has the same error;
Error using sendmail (line 164)
Unknown SMTP host:;

Comment only
25 Apr 2016 Dan

Dan (view profile)

This still can work with gmail, you just have to disable Gmail's new extra security.

31 Mar 2016 Christopher Conatser

Worked until toward the end of 2015. Now I get the same errors as Paul and Brando Miranda.

Comment only
09 Feb 2016 Paul

Paul (view profile)

gmail gave me this error-

Someone just tried to sign in to your Google Account from an app that doesn't meet modern security standards.

21 Jan 2016 Brando Miranda

It didn't work for me. It said:

Error using sendmail (line 171)
Authentication failed.

Error in send_text_message (line 78)

Comment only
13 Dec 2015 William Grefe

Worked perfectly for long simulations and tests

Comment only
26 Mar 2015 trista abuzer


Comment only
03 Mar 2015 Ash

Ash (view profile)

12 Feb 2015 Joseph Malle

Avesome! I changed the carrier section to this which seems to work:


emailTo = regexp(lower(x),'[a-z0-9_.]+@[a-z0-9_.]+\.(com|net)','match','once');

The website says this service has a costs, but I've been able to just do this which I got from stackoverflow without entering payment info. Wouldn't recommend doing it for anything more than personal use...

22 Jan 2015 Maziyar

Very helpful. Thanks for sharing.

30 May 2014 Ford Creighton

12 Jul 2013 Frederic

I found this website that list a bunch of providers for Canada

Comment only
14 Jun 2013 Nagabhushan KC

Ke Feng,

Could you please let me know steps to execute this file?.


12 Jan 2013 Preecha

thank you

04 Jan 2013 Riley

Riley (view profile)

Whenever I try to use this script, I get an error message saying "Undefined function or variable 'sprint'." Any help would be greatly appreciated!

Comment only
22 Apr 2012 Atul Ingle

13 Apr 2012 Semin Ibisevic

13 Apr 2012 Semin Ibisevic

10 Mar 2012 John Pritchard


Comment only
12 Feb 2012 Nathan

Nathan (view profile)

This simple function is extremely useful if you have simulations that take an indeterminate amount of time to finish. I put a call to this function at the end of my neural network training scripts and go get coffee while it runs. It is also easy to modify to send yourself an e-mail instead. The one thing I still need to try is using this to send variable status updates as a code runs, but I think it provides the architecture to do so.

Great code!

12 Feb 2012 Nathan

Nathan (view profile)

10 Jan 2012 Bob Schafer

Just a note that AT&T has changed their email-to-text info, so line ~47 should now read:

case 'att'; emailto = strcat(number,'');

12 Sep 2011 Mr Smart

12 Aug 2011 K E

K E (view profile)

A very useful part of this submission is the permission setup (setpref) for Gmail. Matlab's documentation did not result in my being able to send texts from Gmail, but Ke Feng's permissions did. Interestingly I can text all kinds of carriers from my Gmail account but not from my work email, maybe because the authentication level is higher. If you have to text a bunch of people on different carriers and are having trouble, try doing it from Gmail using Ke Feng's permissions.

30 Oct 2009 Alec

Alec (view profile)

I get the ??? Error using ==> sendmail at 168
Exception reading response;
Connection reset
also... Gmail must have changed the port #...

Comment only
01 Oct 2009 Brian Keats

Brian Keats (view profile)

I get the following error:
??? Error using ==> sendmail at 168
Exception reading response;
Connection reset
Anyone know how to fix it?

Comment only
13 Jun 2009 Greg

Greg (view profile)

I get the same error message

??? Error using ==> sendmail
Could not establish connection with on port 25.

Comment only
11 Jun 2009 Rene

Rene (view profile)

dont work at all

??? Error using ==> sendmail at 168
Could not connect to SMTP host:, port: 25;
Connection timed out: connect

Error in ==> send_text_message at 82

10 Jun 2009 Sherif

Sherif (view profile)

Excellent work.
I am in Canada, and my cell company is Rogers, and the email address they use is ''. I added the following line, and it worked fine.

case 'rogers'; emailto = strcat(number,'');

06 Mar 2009 farah

farah (view profile)

How to set the number...
it give me an error
??? Input argument "number" is undefined.

Error in ==> send_text_message at 38
number = strrep(number, '-', '');

Comment only
13 May 2008 Jason Merrill

As an alternative, follow these instructions to set up sendmail:

and then use, a free e-mail to SMS converter:

sendmail('','','Calculation Finished')

Comment only
02 Mar 2008 saint pierre gadiano


Comment only
17 Feb 2008 vatsla k

23 Jan 2008 Yokesh R

15 Jan 2008 Steve Harston

When I try this code I get the following error:

??? Java exception occurred: Connection reset

at Source)

at Source)

at Source)

Error in ==> sendmail>readmsg at 377

Error in ==> sendmail at 125
[status, code] = okSMTP(readmsg(in));

I know that it has something to do with accessing the email account and I have tried setting different properties but the error is still occurring. Does anyone have any idea how to fix this? Thanks

Comment only
09 Jan 2008 Santiago Balestrini

This is a great script! Well documented too!

I would like to see something done about the password too, my solution was to create an account in Gmail for our entire lab. If anybody messes with it, I can just create a new account.

17 Dec 2007 Bassam Abdelnabi

06 Dec 2007 tariq-tam TAM

06 Dec 2007 tariq tam

thank you

Comment only
05 Dec 2007 janet looloo


Comment only
29 Oct 2007 Robert Flight

Looks pretty good, but a couple of comments. This should work for anyone who has a gmail account, and knows the email address that their cell carrier uses for text messaging. For example, I am in Canada, and my cell company is Aliant, and the email address they use is ''. Therefore I can easily add a case 'aliant', with the address '', and it will work fine for me.

I would also recommend creating two matlab *.mat files, one containing the password (named something cryptic) and the email address to send to, thereby making it a little bit harder for someone to get your password.

01 Oct 2007 Nick C

This would be awsome if I were in the US :(

Comment only
01 Oct 2007 Kelly Kearney

This is an excellent solution to the frustrations associated with running models overnight, only to discover the next morning that something crashed an hour after it started. Very well-documented and easy to use.

Contact us