Text message / E-mail Matlab!

Version 1.0.0.0 (333 Bytes) by Stefan Novak
Send a text message or e-mail to a Gmail account and have Matlab evaluate it and return the results.
1.3K Downloads
Updated 20 Dec 2008

No License

Have you ever had a need to invert a matrix while out for dinner? Have you ever had the need to solve a second-order differential equation while stuck in traffic but didn't have access to Matlab? Well, now you can!

This is a VBA module file (*.bas) that allows you to evaluate a string in Matlab by calling the Matlab interface. In order to get it fully functional, you have to integrate it with Microsoft Outlook by using the following steps:

Step 1) Make a Gmail account of your choice.
Step 2) Add the Gmail account to Microsoft Outlook via Gmail's IMAP interface.
Step 3) Open the Visual Basic Editor. (Alt-F11)
Step 4) Add the Matlab Server Automation... Reference. (Tools > References)
Step 5) Double click the ThisOutlookSession module in the Project window.
Step 6) In the left pull-down menu for the module window, select Application. In the right pull-down menu, select NewMailEx.
Step 7) You have to use a function that (safely) bypasses some of VBA's security dialogs. Use the following code for NewMailEx:

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim iMsg, iConf, Flds
Dim varEntryIDs
Dim objItem
Dim i As Integer
Dim matlabStr As String

Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = "your.gmail.user.name@gmail.com"
Flds.Item(schema & "sendpassword") = "your.gmail.password"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update

varEntryIDs = Split(EntryIDCollection, ",")

For i = 0 To UBound(varEntryIDs)

strID = varEntryIDs(i)
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)

matlabStr = EvalStrInML(olMail.Body)
matlabStr = Replace(matlabStr, Chr(10), "<br>")

With iMsg
.To = olMail.SenderEmailAddress
.From = "Your Name <your.gmail.user.name@gmail.com>"
.Subject = "Matlab Results"
.HTMLBody = "<br>" & ">> " & olMail.Body & "<br>" & matlabStr
.Sender = "Your Name"
.Organization = ""
.ReplyTo = "your.gmail.user.name@gmail.com"
Set .Configuration = iConf
SendEmailGmail = .Send
End With

Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

Next

Set olMail = Nothing
Set olNS = Nothing
End Sub

Step 8) Right-click the Modules folder on the Project panel and click Import File. Select the *.bas file EvalStrInML.bas file.

Step 9) Change your Send/Receive settings to check for e-mail every 1 minute.

You should be good to go! Any e-mails that gets sent to your.gmail.user.name@gmail.com will show up in your Outlook account. When they do, Outlook will parse the body of the e-mail and send it over to Matlab for evaluation. Outlook then takes the results and sends an e-mail back out through your Gmail account.

Here's an example:

From: Stefan Novak <*********@gmail.com>
To: My Matlab Email Interface <*********@gmail.com>
Subject: Let's try a test!
Body: inv([5,8,2;4,10,2;9,3,7])

The reply:

From: My Matlab Email Interface <********@gmail.com>
To: Stefan Novak <*********@gmail.com>
Subject: Matlab Results
Body:
>> inv([5,8,2;4,10,2;9,3,7])

ans =

0.7619 -0.5952 -0.0476
-0.1190 0.2024 -0.0238
-0.9286 0.6786 0.2143

Note: This also works with text messages (as long as your phone is capable of text messaging e-mail address.)

Cite As

Stefan Novak (2026). Text message / E-mail Matlab! (https://www.mathworks.com/matlabcentral/fileexchange/22502-text-message-e-mail-matlab), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Version Published Release Notes
1.0.0.0