Skip to content

Automated emails functionality #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 17, 2025
Merged

Automated emails functionality #4

merged 8 commits into from
Apr 17, 2025

Conversation

jespiron
Copy link
Member

@jespiron jespiron commented Mar 22, 2025

Usage: attendance email-absentees <MODE> <WEEK>

Single Week Mode:

attendance email-absentees single-week 5

Cumulative Mode:

attendance email-absentees cumulative <AFTER_WEEK> --min-absences <MIN_ABSENCES>

To add a new email template, create a section [templates.name_of_template] in config.toml:

[templates.weekly]
subject = "98008 Unexcused Absence"
body_path = "templates/email_weekly_body.html"

[templates.cumulative]
subject = "98008 Danger Zone for Attendance"
body_path = "templates/email_cumulative_body.html"

Then implement its respective filter function for email_absentees_generic.

To test:

  1. Replace sender email in config.toml with your gmail
  2. Enable 2FA for your gmail
  3. Generate password from https://security.google.com/settings/security/apppasswords
  4. Paste password into .env file
diesel setup
cargo run setup
cargo run week 1 mark-absent
cargo run week 2 mark-absent
cargo run email-absentees 1 2
y

...you should see that the email has been sent. If you'd like to see how it looks on the sender's end, edit ./examples/roster.csv to use your test email addresses.

Any response other than y should cancel the operation.

Some other changes:

  • Added .env to gitignore and replaced with .env.example
  • Moved roster.csv into config.toml

@jespiron jespiron mentioned this pull request Mar 22, 2025
4 tasks
@jespiron jespiron requested a review from connortsui20 March 22, 2025 04:31
Copy link
Member

@connortsui20 connortsui20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I think a few adjustments and I can merge this into the other branch.

Comment on lines 1 to 10
<!DOCTYPE html>
<html>
<style>
</style>
<p>Hello!</p>
<p>If you're reading this, our records show that you have an unexcused absence for our most recent class! If you think this is a mistake, no worries, please reply to this email and we'll sort it out together.</p>
<p>If you did miss class, please reply so we can work together to get you back on track. Whether you're seeking help with course material or navigating personal challenges, we're here to support your success!<p>
<p>Best,</p>
<p>98008 Staff 🦀</p>
</html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use the email builder instead to build these emails? We should aim to be telling people how many times they have been absent, for example if they are at 2 absences then that should be a different message.

https://docs.rs/lettre/latest/lettre/transport/index.html

Copy link
Member Author

@jespiron jespiron Mar 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I previously used lettre, but the emails weren't sending, so I switched back to raw SMTP.
I can integrate lettre with enough plumbing, but I don't have bandwidth

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I introduced an email mode. Now we can send different templates with custom filtering functions based on the desired mode
See PR description for usage

src/main.rs Outdated
Comment on lines 40 to 41
/// The minimum number of absences to trigger an email
min_absences: i32,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should want to email absentees for a specific week (not every person who has been absent after week 4), so this should be under the week args

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I introduced an email mode. Now we can send different templates with custom filtering functions based on the desired mode
See PR description for usage

@jespiron jespiron requested a review from connortsui20 March 23, 2025 21:07
Base automatically changed from backend to main March 26, 2025 16:46
Copy link
Member

@connortsui20 connortsui20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@connortsui20 connortsui20 merged commit 9cfb2c8 into main Apr 17, 2025
@connortsui20 connortsui20 deleted the jess/backend-edits branch April 17, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants