From bd3ef1291be949256755b4f117d0c3020a67bbbe Mon Sep 17 00:00:00 2001 From: janekhuong Date: Thu, 30 Oct 2025 12:54:25 -0400 Subject: [PATCH 1/2] Added script for sending interest form emails --- scripts/interest_form_emails.py | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 scripts/interest_form_emails.py diff --git a/scripts/interest_form_emails.py b/scripts/interest_form_emails.py new file mode 100644 index 00000000..0edce1b5 --- /dev/null +++ b/scripts/interest_form_emails.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import os +import sys +import csv +import time +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail + +FROM_EMAIL = "contact@mchacks.ca" +TEMPLATE_ID = "d-8cbb9f9e07f04712bc88aecba33d49f3" + + +def send_email(to_email): + + message = Mail( + from_email=FROM_EMAIL, + to_emails=to_email, + ) + message.template_id = TEMPLATE_ID + + try: + sg = SendGridAPIClient(os.getenv("SENDGRID_API_KEY")) + response = sg.send(message) + return True + except Exception as e: + print(f"Error sending to {to_email}: {e}") + return False + + +def parse_csv(csv_filename): + if not os.path.exists(csv_filename): + print(f"Error: File '{csv_filename}' not found") + return + + sent_count = 0 + failed_count = 0 + + try: + with open(csv_filename, "r", newline="", encoding="utf-8") as csvfile: + reader = csv.DictReader(csvfile) + + for _, row in enumerate(reader, start=1): + email = row.get("Email", "").strip() + + if not email or "@" not in email: + continue + + if send_email(email): + sent_count += 1 + else: + failed_count += 1 + + time.sleep(0.1) # Add delay to avoid rate limiting + + print(f"\nSent: {sent_count} | Failed: {failed_count}") + + except Exception as e: + print(f"Error: {e}") + + +if __name__ == "__main__": + parse_csv(sys.argv[1]) From e29ad9e0f131da8375c6330bc3ce4d68cb9558f6 Mon Sep 17 00:00:00 2001 From: janekhuong Date: Thu, 30 Oct 2025 13:05:12 -0400 Subject: [PATCH 2/2] Usage comments --- scripts/interest_form_emails.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/interest_form_emails.py b/scripts/interest_form_emails.py index 0edce1b5..8126ec91 100644 --- a/scripts/interest_form_emails.py +++ b/scripts/interest_form_emails.py @@ -1,4 +1,14 @@ #!/usr/bin/env python3 +""" +This script sends templated emails to a list of recipients from a CSV file. + +USAGE: + python interest_form_emails.py + +REQUIREMENTS: + - CSV file must contain an "Email" column with valid email addresses +""" + import os import sys import csv @@ -50,7 +60,7 @@ def parse_csv(csv_filename): else: failed_count += 1 - time.sleep(0.1) # Add delay to avoid rate limiting + time.sleep(0.1) # Add delay to avoid rate limiting print(f"\nSent: {sent_count} | Failed: {failed_count}")