Skip to content

Commit 7492d8b

Browse files
committed
fix: replyTo and email from name
1 parent f4a08f2 commit 7492d8b

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

src/jobs/auth-verification-email.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ export const sendAuthVerificationEmail = async (
1515
) => {
1616
const { email, token } = payload;
1717
const baseUrl = env.NEXT_PUBLIC_BASE_URL;
18-
1918
const confirmLink = `${baseUrl}/verify-email/${token}`;
2019

21-
console.log("Sending email to ", email, "with link ", confirmLink);
22-
2320
const html = await render(
2421
AccountVerificationEmail({
2522
verifyLink: confirmLink,

src/jobs/esign-confirmation-email.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type ConfirmationEmailPayloadType = {
88
fileUrl: string;
99
documentName: string;
1010
senderName: string | null;
11+
senderEmail: string | null;
1112
company: {
1213
name: string;
1314
logo?: string | null;
@@ -23,11 +24,13 @@ export const sendEsignConfirmationEmail = async (
2324
documentName: payload.documentName,
2425
recipient: payload.recipient,
2526
senderName: payload.senderName,
27+
senderEmail: payload.senderEmail,
2628
company: payload.company,
2729
}),
2830
);
2931
await sendMail({
3032
to: payload.recipient.email,
33+
...(payload.senderEmail && { replyTo: payload.senderEmail }),
3134
subject: "Completed e-signed documents from all parties",
3235
html,
3336
attachments: [
@@ -36,6 +39,10 @@ export const sendEsignConfirmationEmail = async (
3639
path: payload.fileUrl,
3740
},
3841
],
42+
43+
headers: {
44+
"X-From-Name": payload.senderName || "Captable",
45+
},
3946
});
4047
};
4148

src/jobs/esign-email.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type ExtendedEsignPayloadType = EsignEmailPayloadType &
3333
AdditionalPayloadType;
3434

3535
export const sendEsignEmail = async (payload: ExtendedEsignPayloadType) => {
36-
const { email, token, ...rest } = payload;
36+
const { email, token, sender, ...rest } = payload;
3737
const baseUrl = env.NEXT_PUBLIC_BASE_URL;
3838
const html = await render(
3939
EsignEmail({
@@ -43,8 +43,12 @@ export const sendEsignEmail = async (payload: ExtendedEsignPayloadType) => {
4343
);
4444
await sendMail({
4545
to: email,
46-
subject: "eSign Link",
46+
...(sender?.email && { replyTo: sender.email }),
47+
subject: "eSign Document Request",
4748
html,
49+
headers: {
50+
"X-From-Name": sender?.name || "Captable",
51+
},
4852
});
4953
};
5054

src/jobs/share-data-room-email.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export const sendShareDataRoomEmail = async (
3939
link,
4040
}),
4141
),
42+
43+
headers: {
44+
"X-From-Name": senderName,
45+
},
4246
});
4347
};
4448

src/jobs/share-update-email.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export const sendShareUpdateEmail = async (payload: UpdateSharePayloadType) => {
3939
link,
4040
}),
4141
),
42+
43+
headers: {
44+
"X-From-Name": senderName,
45+
},
4246
});
4347
};
4448

src/server/mailer.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ const getTransport = () => {
1212
});
1313
};
1414

15+
type RecordType = Record<string, string | undefined>;
16+
1517
export const sendMail = (options: Omit<SendMailOptions, "from">) => {
18+
let from = `Captable <${env.EMAIL_FROM}>`;
19+
const headers = (options.headers || {}) as RecordType;
20+
21+
const senderName = headers["X-From-Name"];
22+
23+
if (senderName) {
24+
from = `${senderName} <${env.EMAIL_FROM}>`;
25+
}
26+
1627
const transport = getTransport();
1728
return transport.sendMail({
18-
from: env.EMAIL_FROM,
29+
from,
1930
...options,
2031
});
2132
};

src/trpc/routers/template-router/procedures/sign-template.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ export const signTemplateProcedure = withoutAuth
203203
});
204204
const email = nextDelivery.email;
205205

206-
const uploaderName = template.uploader.user.name;
206+
const uploader = template.uploader.user;
207+
const uploaderName = uploader.name;
207208

208209
await EsignAudit.create(
209210
{
@@ -230,7 +231,7 @@ export const signTemplateProcedure = withoutAuth
230231
documentName: template.name,
231232
recipient: nextDelivery,
232233
company: template.company,
233-
sender: template.uploader.user,
234+
sender: uploader,
234235
});
235236
}
236237
}

0 commit comments

Comments
 (0)