4d01e13a84
* Revert "Revert structured logging 2 (#1240)"
This reverts commit 78ecaeffcb.
* Logging should not be bundled into core shared directory
* making sure observability stuff isnt bundled into frontend
Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
42 lines
810 B
TypeScript
42 lines
810 B
TypeScript
import { logger } from '@/logging/logging'
|
|
import { getTransporter } from '@/modules/emails/utils/transporter'
|
|
|
|
export type SendEmailParams = {
|
|
from?: string
|
|
to: string
|
|
subject: string
|
|
text: string
|
|
html: string
|
|
}
|
|
|
|
/**
|
|
* Send out an e-mail
|
|
*/
|
|
export async function sendEmail({
|
|
from,
|
|
to,
|
|
subject,
|
|
text,
|
|
html
|
|
}: SendEmailParams): Promise<boolean> {
|
|
const transporter = getTransporter()
|
|
if (!transporter) {
|
|
logger.error('No email transport present. Cannot send emails.')
|
|
return false
|
|
}
|
|
try {
|
|
const emailFrom = process.env.EMAIL_FROM || 'no-reply@speckle.systems'
|
|
return await transporter.sendMail({
|
|
from: from || `"Speckle" <${emailFrom}>`,
|
|
to,
|
|
subject,
|
|
text,
|
|
html
|
|
})
|
|
} catch (error) {
|
|
logger.error(error)
|
|
}
|
|
|
|
return false
|
|
}
|