This is a python code to send each student's grade privately using
smtplib
to send emails from python and csv
to deal with CSV file
of grades and students' names.
As you can see in sample.csv you should have a sheet like this (if your column names are different feel free to change them in code):
FIRST_NAME_COLUMN = "نام"
LAST_NAME_COLUMN = "نام خانوادگی"
STUDENT_ID_COLUMN = "شماره دانشجویی"
EMAIL_COLUMN = "ایمیل"
NOTE_COLUMN = "توضیحات"
SKIPPED_ROWS = 2
Then you can fill subject.txt and body.html with the text that you want to send as your email subject and its body. e.g.
<html>
<body dir="rtl">
<p>
با سلام<br />
دانشجوی عزیز {{ name }}<br />
نمره تمرین شما
</p>
<table>
<tbody>
{% for name, grade in grades.items() %}
<tr>
<td>{{ name }}</td>
<td>{{ grade }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<p>
در صورت هرگونه اعتراض یا مشکلی با ایمیل زیر در تماس باشید.<br />
<a href="mailto:[email protected]">Pahram Alvani</a>
</p>
</body>
</html>
As you can see, this is a Jinja template, and you have variables that is set for each student.
Please note that you can check the emails before actually sending them with --dry-run
flag.
After fixing sheets and changing TXT files, run the program and enter your SMTP address and after that your email address and its password in configuration file. e.g.
---
email:
server: smtp.gmail.com
username: [email protected]
password: secret
Note that if you use Gmail you must go to your Google account and change Less secure app access here by turning on Allow less secure apps. Otherwise, you need to use application-specific passwords.
You just need to install pandas using pip to run this program.
pip install .
cp config.example.yml config.yml
python3 harpocrates
Here you can see some examples of emails I sent from sample CSV files: