import type { Message } from "./message" ; import getPool from "@cocalc/database/pool" ; import sendViaSMTP from "./smtp" ; import sendViaSendgrid from "./sendgrid" ; import sendEmailThrottle from "./throttle" ; export default async function sendEmail ( message , account_id ? ) { const pool = getPool ( "long" ) ; await sendEmailThrottle ( account_id ) ; const { rows } = await pool . query ( "SELECT value FROM server_settings WHERE name='email_backend'" ) ; if ( rows . length == 0 ) { throw Error ( "no email backend is configured" ) ; } const { value } = rows [ 0 ] ; if ( value == "smtp" ) { await sendViaSMTP ( message ) ; } else if ( value == "sendgrid" ) { await sendViaSendgrid ( message ) ; } else { throw Error ( "no valid email backend configured" ) ; } }