2

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.

Tom De Vries
  • 3,758
  • 18
  • 36

1 Answers1

5

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.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355