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$
2
  • $\begingroup$ Have you tried using NotebookImport? $\endgroup$
    – Carl Woll
    Commented Mar 21, 2017 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$ Commented Mar 21, 2017 at 20:04

1 Answer 1

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 and acknowledge you have read our privacy policy.

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