Skip to content

Commit

Permalink
Merge pull request #734 from bigcapitalhq/hook-up-cc-bcc-to-mail-sender
Browse files Browse the repository at this point in the history
fix: hook up cc and bcc fields to mail sender
  • Loading branch information
abouolia authored Nov 2, 2024
2 parents bd5e338 + 5190582 commit ba1d9b3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packages/server/src/lib/Mail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default class Mail {
subject: string = '';
content: string = '';
to: string | string[];
cc: string | string[];
bcc: string | string[];
from: string = `${process.env.MAIL_FROM_NAME} ${process.env.MAIL_FROM_ADDRESS}`;
data: { [key: string]: string | number };
attachments: IMailAttachment[];
Expand All @@ -20,6 +22,8 @@ export default class Mail {
return {
to: this.to,
from: this.from,
cc: this.cc,
bcc: this.bcc,
subject: this.subject,
html: this.html,
attachments: this.attachments,
Expand Down Expand Up @@ -60,6 +64,16 @@ export default class Mail {
return this;
}

setCC(cc: string | string[]) {
this.cc = cc;
return this;
}

setBCC(bcc: string | string[]) {
this.bcc = bcc;
return this;
}

/**
* Sets from address to the mail.
* @param {string} from
Expand All @@ -72,7 +86,7 @@ export default class Mail {

/**
* Set attachments to the mail.
* @param {IMailAttachment[]} attachments
* @param {IMailAttachment[]} attachments
* @returns {Mail}
*/
setAttachments(attachments: IMailAttachment[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class SendSaleEstimateMail {
mailOptions: SaleEstimateMailOptions
): Promise<SaleEstimateMailOptions> => {
const formatterArgs = await this.formatterArgs(tenantId, saleEstimateId);

const formattedOptions =
await this.contactMailNotification.formatMailOptions(
tenantId,
Expand Down Expand Up @@ -166,6 +165,8 @@ export class SendSaleEstimateMail {
const mail = new Mail()
.setSubject(formattedOptions.subject)
.setTo(formattedOptions.to)
.setCC(formattedOptions.cc)
.setBCC(formattedOptions.bcc)
.setContent(formattedOptions.message);

// Attaches the estimate pdf to the mail.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export class SendSaleInvoiceMail {
const mail = new Mail()
.setSubject(formattedMessageOptions.subject)
.setTo(formattedMessageOptions.to)
.setCC(formattedMessageOptions.cc)
.setBCC(formattedMessageOptions.bcc)
.setContent(formattedMessageOptions.message);

// Attach invoice document.
Expand All @@ -89,7 +91,6 @@ export class SendSaleInvoiceMail {
{ filename: `${invoiceFilename}.pdf`, content: invoicePdfBuffer },
]);
}

const eventPayload = {
tenantId,
saleInvoiceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ export class SendPaymentReceiveMailNotification {
const mail = new Mail()
.setSubject(parsedMessageOpts.subject)
.setTo(parsedMessageOpts.to)
.setCC(parsedMessageOpts.cc)
.setBCC(parsedMessageOpts.bcc)
.setContent(parsedMessageOpts.message);

const eventPayload = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export class SaleReceiptMailNotification {
const mail = new Mail()
.setSubject(parsedMessageOpts.subject)
.setTo(parsedMessageOpts.to)
.setCC(parsedMessageOpts.cc)
.setBCC(parsedMessageOpts.bcc)
.setContent(parsedMessageOpts.message);

// Attaches the receipt pdf document.
Expand Down

0 comments on commit ba1d9b3

Please sign in to comment.