Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"jspdf": "^4.2.1",
"jspdf-autotable": "^5.0.2",
"luxon": "^3.7.2",
"nodemailer": "^8.0.11",
"openai": "^6.17.0",
"zod": "^3.25.76"
},
Expand All @@ -46,6 +47,7 @@
"@types/luxon": "^3.4.2",
"@types/mocha": "^10.0.7",
"@types/node": "^22",
"@types/nodemailer": "^8.0.0",
"@types/sinon": "^21.0.0",
"@typescript-eslint/eslint-plugin": "^8.54.0",
"@typescript-eslint/parser": "^8.54.0",
Expand All @@ -70,4 +72,4 @@
"serialize-javascript": "^7.0.4",
"http-proxy-agent": "^7.0.2"
}
}
}
44 changes: 44 additions & 0 deletions functions/src/functions/hourlyTestEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This source file is part of the MyHeart Counts project
//
// SPDX-FileCopyrightText: 2026 Stanford University and the project authors (see CONTRIBUTORS.md)
// SPDX-License-Identifier: MIT

import { logger } from "firebase-functions/v2";
import { onSchedule } from "firebase-functions/v2/scheduler";
import nodemailer from "nodemailer";
import { defaultServiceAccount } from "./helpers.js";

const senderAddress = "myheartcounts@stanford.edu";
const recipientAddress = "goldschmidt@stanford.edu";

export const sendTestEmail = async (): Promise<void> => {
// GCP blocks outbound port 25, so we default to 587 with STARTTLS
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST ?? "smtp.stanford.edu",
port: Number(process.env.SMTP_PORT ?? 587),
secure: false,
});

const info = await transporter.sendMail({
from: `"MyHeart Counts" <${senderAddress}>`,
to: recipientAddress,
subject: "MyHeart Counts SMTP relay test",
text: `This is an automated hourly test email from the MyHeart Counts Firebase functions, sent at ${new Date().toISOString()}.`,
});
logger.info(`Test email sent to ${recipientAddress}: ${info.response}`);
};

export const hourlyTestEmail = onSchedule(
{
schedule: "every 1 hours",
timeZone: "UTC",
serviceAccount: defaultServiceAccount,
},
async (_event) => {
try {
await sendTestEmail();
} catch (error) {
logger.error("Failed to send test email:", error);
}
},
);
1 change: 1 addition & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ export * from "./functions/processUserDeletions.js";
// trigger is back and backfill has populated the target docs.
// export * from "./functions/processPendingHealthSampleDeletions.js";
export * from "./functions/backfillExtendedActivityNudgesOptIn.js";
export * from "./functions/hourlyTestEmail.js";
Loading