Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sometimes Mathematica takes quite a while to finish calculations and it would be convenient to be able to move away from the computer while it is working. I was wondering if there is any "clever" hack that can be used purely within Mathematica to e-mail updates on the computation.

I can think of a very rough way of getting an update other than actually accessing the machine, which would be by exporting some output to a file in Dropbox. From another machine connected to Dropbox I could see when the file is updated. But this seems to me like a very ugly solution.

A less ugly solution would be to write an external script, probably with python, and then have Mathematica run it at some point in the calculation. This would allow for both e-mail and text message updates (using Skype or a similar service and the appropiate python modules).

Is there any way to do something similar purely within Mathematica?

share|improve this question
2  
SendMail is the API supported by M but you need to find one open SMTP server to send your mail. Internet is full of these, if you know how to find. –  Rorschach Aug 9 '13 at 18:59
    
related –  cormullion Aug 9 '13 at 18:59
    
There are services with which you can easily send text messages. They use REST APIs so you can interact with them using for example URLFetch. –  Pickett Aug 9 '13 at 19:07
    
An even better idea is if these computations take awhile schedule them for when you are drinking beer :) So don;t even bother starting them and then moving away from computer. Combine ScheduleTask and friends with some of the email solutions you get below. For scheduling when Mathematica is not already running here is an example (that can also be combined with email): library.wolfram.com/infocenter/MathSource/7590. So you are out having a beer and u get a message saying computation done. Maybe even an attachment of a plot. –  Mike Honeychurch Aug 9 '13 at 21:39

4 Answers 4

I like to use the docked cells for this purpose. I create two buttons in my "heavy processing" notebooks:

enter image description here

  • the first is a bell that rings thrice when the computation is finished — used to alert me when I'm at my computer, but doing something else.

  • the second is to send an email to myself when the processing is finished – used when I'm away from my computer, but online (on iPad or a different machine)

Both of them are Buttons with a queued evaluation, so as to prevent the front end from evaluating it pre-emptively (i.e., it will evaluate only after the processing is finished).

You use these buttons by first evaluating (ShiftEnter) all the cells that you want processed and then click the desired button and walk away.

The code for this is below:

With[{
    bell = Import["http://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Bell_alt_font_awesome.svg/200px-Bell_alt_font_awesome.svg.png"], 
    email = Import["http://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Aiga_mail.svg/200px-Aiga_mail.svg.png"], 
    ir = ImageResize[#, {16, 16}] &},

    SetOptions[EvaluationNotebook[], 
        DockedCells -> Cell[BoxData@ToBoxes@Row[{
            Button[ir@bell, 
               Do[EmitSound[Sound[SoundNote[]]]; Pause[0.5], {3}], 
               Method -> "Queued", Appearance -> "Palette"],
            Spacer@5,
            Button[ir@email, 
                SendMail[
                    "From" -> "me@domain.com", 
                    "To" -> "myself@domain.com", 
                    "Subject" -> "Finished processing!", "Body" -> "", 
                    "Server" -> "mail.domain.com"
                ], 
                Method -> "Queued", Appearance -> "Palette"]
        }]]
    ]
 ]

Use additional options to SendMail as necessary, depending on your email provider.

share|improve this answer
1  
Could also set $Post to get feedback at every output as in $Post = (Do[EmitSound[Sound[SoundNote[]]]; Pause[0.5], {3}]; #) &; –  Sjoerd C. de Vries Aug 9 '13 at 19:59
2  
I can't believe you missed hitting 200 "yesterday" with an answer like this. +1 for today. –  Mr.Wizard Aug 10 '13 at 0:34
    
@Mr.Wizard Thanks :) –  rm -rf Aug 10 '13 at 0:35
    
Neat answer, recently linked. +1 –  rasher Mar 31 at 1:09

As stated in this answer you can do the following to send an email form Mathematica. Because of the nature of how email servers are set up you will have to have some server that sends the email.

SendMail[
 "To" -> "YYY...@me.com",
 "Subject" -> "Example Message",
 "Body" -> "My text",
 "From" -> "xxx...@gmail.com",
 "Server" -> "smtp.gmail.com",
 "UserName" -> "xxx...@gmail.com",
 "Password" -> Automatic,
 "PortNumber" -> 587,
 "EncryptionProtocol" -> "StartTLS"
 ]

Depending on what type of service you are on you should be able to send text messages through your email by appending @emailprovider.com

For example:

US Cellular: email.uscc.net
Verizon: vtext.com
Virgin: vmobl.com
AT&T: txt.att.net
Nextel: messaging.nextel.com
Sprint: messaging.sprintpcs.com
T-Mobile: tmomail.net

Read more: How to Send a Text Message from Email

share|improve this answer

Reference

If you want results emailed then why not combine that with scheduling of the job? So in other words if you have computations that take awhile or you run regularly why hang around or why even be there to get them started?

More efficient use of time is to schedule the job and go and do something else. Have the job run while you are sleeping and get the results emailed and check on your phone when you wake up.

Create a *.m file containing code like this:

p1 = Plot[Sin[x], {x, -Pi, Pi}];
Export["result plot.png", p1];
SendMail["From" -> "i.newton@gravity.com", 
  "To" -> "w.heisenberg@uncertainty.com", "ReplyTo" -> "", 
  "Subject" -> "How is the beer?", 
  "Body" -> "Here are the results of your scheduled task", 
  "Password" -> "xxxxx", "EncryptionProtocol" -> "SSL", 
  "PortNumber" -> 465, "Server" -> "smtp.gravity.com", 
  "Attachments" -> {"result plot.png"}];

and call it task.m and then run this file at a scheduled time (i.e. some time after beer o'clock)

RunScheduledTask[<< "task.m", {1}, AbsoluteTime[{2013, 8, 10, 17, 27, 0}]]

ScheduledTask and co requires Mathematica to be running but you can also use your systems scheduler to switch Mathematica on and off. Here is how to do it on Macs as of about 3.5 years ago (it may need updating)

share|improve this answer

If you want to get a text message on your cellphone when the calculation is done, you need a little bit more structure than what Mathematica has built in, but it's not too hard to do.

I use IFTTT - "if this, then that", pronounced ift as in 'gift'. It's a free service which can do all sorts of things, to turn one sort of 'trigger' into an action on some other channel. It's quite easy to make a 'recipe' like this:

enter image description here

Arrange for Mathematica to send an email (using one of the multiple fine answers in this thread) to trigger@ifttt.com that contains the hashtag text "#Mathematica" in the subject line. (Make sure the "From" in your SendMail agrees with what you declare to ifttt, too.) You can then arrange for ifttt to send a text message to your phone with a bunch of information pulled from the email:

enter image description here

To be honest I haven't used this in a while but I have a feeling I'll be using it again soon enough. Full disclaimer: I am not in any way associated with ifttt - I just find it useful. I'm pretty sure there are other ways of sending SMS through online APIs that can be accessed either directly or through e.g. Python scripts, but this one is fairly simple.

share|improve this answer
    
If this post is not to your liking - enough to give it a downvote - then please explain your reasons for it. Thanks! –  episanty Sep 9 '13 at 9:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.