Expanding on the concept from Send email from command line (macOS Monterey 12.3) which was linked to in a comment,
If your CSV file is simple, you can probably just loop over it in a shell script.
#!/bin/bash
while IFS="," read -r email firstname lastname course grade; do
# The lines after this one need to be indented by a tab
mail -s "Your grade for $course" "$email" <<-\____here
Hello $firstname $lastname!
I am happy to tell you that you passed $course.
Your grade will be $grade
Best,
Prof. Power J. Pete
____here
done <file.csv
(The tab indentation is for human legibility; you can remove the indentation and take out the -
after <<
if you are having trouble with getting literal tabs in there. Unfortunately, Stack Exchange replaces them with spaces here.)
A complication is that some CSV dialects will aggressively add quotes around the values; you will then need to clean up the fields as you read them, or try to switch to a different delimiter (tab-separated values or TSV is often good for this. Then you need IFS=$'\t'
).
In case it's not obvious, the input would be a CSV file with the following data (and no header):
[email protected],Bob Q.,Student,Anthropology 101,B
[email protected],Jane W.,Pupil,Python Asynch and Threading,A
[email protected],Donald,Trump,Ethics 101,F
This crucially requires your Mac to already be configured to send email out of your organization. In some settings, this pesky detail can be the harder part; but many universities etc make this really easy as long as you are within their network or VPN. You just need to know the name of the outbound server (aka smarthost or relayhost, smtp.your.edu
?); the linked question has an answer with more details about how to set up Postfix.