Skip to content

Commit ae3aea9

Browse files
authored
Personalized Name String in E-mails (#449)
* Better attempt at using a personalized string for usernames in emails instead of the generic 'TPEN User' text. * Changes while reviewing * Changes while reviewing * Changes while reviewing
1 parent c2f669e commit ae3aea9

4 files changed

Lines changed: 15 additions & 73 deletions

File tree

.claude/settings.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

.claude/statusline-command.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

classes/Project/Project.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export default class Project {
9393
</p>
9494
`
9595
}
96-
await sendMail(email, `Invitation to ${projectTitle}`, message)
96+
const recipientName = user?.profile?.displayName || email.split("@")[0]
97+
await sendMail(email, `Invitation to ${projectTitle}`, message, recipientName)
9798
return this
9899
} catch (error) {
99100
throw error
@@ -252,7 +253,8 @@ export default class Project {
252253
<p>Your contributions to the project remain attributed to you, but you no longer have access to some TPEN3 data. *Access to RERUM data is not affected.</p>
253254
<p>If you believe this was done in error, please contact a project administrator.</p>`
254255

255-
await sendMail(userData.email, subject, message)
256+
const recipientName = userData?.profile?.displayName || userData?.email?.split("@")[0]
257+
await sendMail(userData.email, subject, message, recipientName)
256258
}
257259
} catch (emailError) {
258260
console.error("Failed to send removal confirmation email:", emailError)

utilities/mailer/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import {fileURLToPath} from "url"
66
const __filename = fileURLToPath(import.meta.url)
77
const __dirname = path.dirname(__filename)
88

9-
export const sendMail = async (email, subject, message) => {
9+
/**
10+
* Send an email using the HTML template.
11+
* @param {string} email - Recipient email address.
12+
* @param {string} subject - Email subject line.
13+
* @param {string} message - HTML message body content.
14+
* @param {string} [userName] - Recipient display name for the greeting.
15+
* @returns {Promise<{status: number, message: string}>}
16+
*/
17+
export const sendMail = async (email, subject, message, userName) => {
1018
if (!email || typeof email !== "string") {
1119
return {
1220
status: 400,
@@ -32,7 +40,8 @@ export const sendMail = async (email, subject, message) => {
3240
const templatepath = path.join(__dirname, "template.html")
3341
let htmlTemplate = fs.readFileSync(templatepath, "utf-8")
3442

35-
htmlTemplate = htmlTemplate.replace("{{userName}}", "TPEN User")
43+
const displayName = userName || email.split("@")[0]
44+
htmlTemplate = htmlTemplate.replace("{{userName}}", displayName)
3645
htmlTemplate = htmlTemplate.replace("{{subject}}", subject)
3746
htmlTemplate = htmlTemplate.replace("{{messageBody}}", message)
3847

0 commit comments

Comments
 (0)