Cancelling classes email

This emails students with SSIs in a class when the last section of the class is cancelled. It also creates a new template for this email. I tested that it emails students with a valid SSI that are not otherwise being emailed.
This duplicates a lot of code from the previous 10 lines.  It looks like the only changes are in the template and the list of students.  Could you just iterate over a list of pairs (template filename, list of students) instead to avoid code duplication?