Reviewed-on: #8 Co-authored-by: Patrick Mueller <patrick@mueller-patrick.tech> Co-committed-by: Patrick Mueller <patrick@mueller-patrick.tech>
This commit was merged in pull request #8.
This commit is contained in:
@@ -13,26 +13,30 @@ export namespace MailService {
|
||||
tls: {rejectUnauthorized: false}
|
||||
});
|
||||
|
||||
const mailConfigurations = {
|
||||
export interface MailAttachment {
|
||||
filename: string;
|
||||
content: string | Buffer;
|
||||
contentType?: string;
|
||||
}
|
||||
|
||||
// It should be a string of sender email
|
||||
from: 'noreply@nachklang.art',
|
||||
export interface SendMailOptions {
|
||||
html?: string;
|
||||
attachments?: MailAttachment[];
|
||||
}
|
||||
|
||||
// Comma Separated list of mails
|
||||
to: 'mail@pmueller.me',
|
||||
|
||||
// Subject of Email
|
||||
subject: '',
|
||||
|
||||
// This would be the text of email body
|
||||
text: ''
|
||||
// Builds a fresh options object per call rather than mutating a shared
|
||||
// module-level one - the transporter is pooled, so overlapping sendMail
|
||||
// calls (e.g. two guests redeeming at once) previously risked one
|
||||
// call's recipient/subject/body being overwritten by another's before
|
||||
// transporter.sendMail() read it.
|
||||
export const sendMail = async (recipientAddress: string, subject: string, body: string, options?: SendMailOptions) => {
|
||||
await transporter.sendMail({
|
||||
from: 'noreply@nachklang.art',
|
||||
to: recipientAddress,
|
||||
subject: subject,
|
||||
text: body,
|
||||
html: options?.html,
|
||||
attachments: options?.attachments
|
||||
});
|
||||
};
|
||||
|
||||
export const sendMail = async (recipientAddress: string, subject: string, body: string) => {
|
||||
mailConfigurations.to = recipientAddress;
|
||||
mailConfigurations.subject = subject;
|
||||
mailConfigurations.text = body;
|
||||
|
||||
await transporter.sendMail(mailConfigurations);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user