2
$\begingroup$

I am trying to automate some procedures for grading and returning student work. It's all online so it's a lot of file management. The specific question is this. Suppose I have an open notebook with comments for the student. Just a few simple text lines, which questions they got wrong, etc.

I can use SendMail to email the student, but how do I copy the contents of that notebook and use them as the BODY of the email? Selecting the contents of the notebook and reading it gives all the cell expressions.

SelectionMove[temp, All, Notebook]
body = NotebookRead[temp]

This doesn't work for the body of the email.

Is there a way to copy the contents of a notebook in a format that would be suitable for the "Body" part of a SendMail command?

I should add that all the other procedures are automated, creating the file, sending comments to the file, who the student is, what their email is, so at the end, after grading their work, everything is in place to send off the email using Mathematica, but I don't know how to get my comments into the body of that email.

$\endgroup$
  • $\begingroup$ Have you tried using NotebookImport? $\endgroup$ – Carl Woll Mar 21 '17 at 19:58
  • $\begingroup$ That is just what I need, if I import as "Text". That is just what I needed, I've only ever used NotebookRead, did not know about NotebookImport. If you post this I would accept it as an answer. $\endgroup$ – Tom De Vries Mar 21 '17 at 20:04
5
$\begingroup$

The function NotebookImport is a nice tool for importing specific cells from a Notebook into a specific form. For example:

NotebookImport[
    Notebook[{
        Cell["This is text", "Text"],
        Cell["2+2", "Input"],
        Cell["And more text", "Text"]
    }],
    "Text"
]

{"This is text", "And more text"}

It' s nice that it works with both explicit Notebook expressions (as above), as well as NotebookObject expressions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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