async function sendSubscriberEmails() {
  const baseUrl = process.env.BASE_URL
  const rawSMTPSettings = process.env.SMTP_SETTINGS
  if (!rawSMTPSettings) {
    throw new ReferenceError('No SMTP settings are defined for the mailer to work')
  }
  if (!baseUrl) {
    throw new ReferenceError('No BASE_URL set, this is required in order to properly link emails back to the system displaying them')
  }
  const mailCredentials = JSON.parse(rawSMTPSettings)

  // getSubscribers(true, false) filters down to only email subscribers
  const results = await getSubscribers(true, false)
  for (const subscriber of results.docs) {
    // TODO make a test to see what happens when keyword or query are null, possibly protect against issues that would
    // stall delivery of mails.
    const response = await getAlertsByQuery(subscriber.query, subscriber.keyword)
    if (response && response.results.length > 0) {
      console.log('Sending email update')
      const email = subscriber.email
      const code = await createCode(email)

      renderAndSendEmail(
        email,
        response.results,
        baseUrl,
        mailCredentials,
        code)
      await subscriberUpdated(subscriber)
    }
  }
}
// This requires setting up the SMTP_SETTINGS environment variable as described in the README.md
This requires setting up the SMTP_SETTINGS environment variable as described in the README.md
This requires setting up the SMTP_SETTINGS environment variable as described in the README . md
async function sendSubscriberEmails() {
  const baseUrl = process.env.BASE_URL
  const rawSMTPSettings = process.env.SMTP_SETTINGS
  if (!rawSMTPSettings) {
    throw new ReferenceError('No SMTP settings are defined for the mailer to work')
  }
  if (!baseUrl) {
    throw new ReferenceError('No BASE_URL set, this is required in order to properly link emails back to the system displaying them')
  }
  const mailCredentials = JSON.parse(rawSMTPSettings)
  const results = await getSubscribers(true, false)
  for (const subscriber of results.docs) {
    const response = await getAlertsByQuery(subscriber.query, subscriber.keyword)
    if (response && response.results.length > 0) {
      console.log('Sending email update')
      const email = subscriber.email
      const code = await createCode(email)
      renderAndSendEmail(
        email,
        response.results,
        baseUrl,
        mailCredentials,
        code)
      await subscriberUpdated(subscriber)
    }
  }
}
async function sendSubscriberEmails ( ) { const baseUrl = process . env . BASE_URL const rawSMTPSettings = process . env . SMTP_SETTINGS if ( ! rawSMTPSettings ) { throw new ReferenceError ( 'No SMTP settings are defined for the mailer to work' ) } if ( ! baseUrl ) { throw new ReferenceError ( 'No BASE_URL set, this is required in order to properly link emails back to the system displaying them' ) } const mailCredentials = JSON . parse ( rawSMTPSettings ) const results = await getSubscribers ( true , false ) for ( const subscriber of results . docs ) { const response = await getAlertsByQuery ( subscriber . query , subscriber . keyword ) if ( response && response . results . length > 0 ) { console . log ( 'Sending email update' ) const email = subscriber . email const code = await createCode ( email ) renderAndSendEmail ( email , response . results , baseUrl , mailCredentials , code ) await subscriberUpdated ( subscriber ) } } }
This requires setting up the SMTP_SETTINGS environment variable as described in the README.md
This requires setting up the SMTP_SETTINGS environment variable as described in the README . md
// getSubscribers(true, false) filters down to only email subscribers // TODO make a test to see what happens when keyword or query are null, possibly protect against issues that would // stall delivery of mails.