How to use the postmark.ServerClient function in postmark

To help you get started, we’ve selected a few postmark examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wildbit / postmark-cli / src / commands / templates / preview.ts View on Github external
const preview = (serverToken: string, args: TemplatePreviewArguments) => {
  const { port, templatesdirectory } = args
  log(`${title} Starting template preview server...`)

  // Start server
  const app = express()
  const server = require('http').createServer(app)
  const io = require('socket.io')(server)

  // Cache manifest and Postmark server
  const client = new ServerClient(serverToken)
  let manifest = createManifest(templatesdirectory)

  // Static assets
  app.use(express.static(`${previewPath}assets`))

  const updateEvent = () => {
    // Generate new manifest
    manifest = createManifest(templatesdirectory)

    // Trigger reload on client
    log(`${title} File changed. Reloading browser...`)
    io.emit('change')
  }

  // Watch for file changes
  createMonitor(untildify(templatesdirectory), { interval: 2 }, monitor => {
github joshwcomeau / tinkersynth / src / server / email.js View on Github external
import React from 'react';
import ReactDOMServer from 'react-dom/server';

import PurchaseIncludingDownload from './email-templates/purchase-incl-download';
import PurchaseJustPhysicalPrint from './email-templates/purchase-just-physical';
import ShippingNotification from './email-templates/shipping-notification';

const postmark = require('postmark');

const SEND_IN_DEV = false;

// Send an email:
var client = new postmark.ServerClient('b79d4a35-93f3-49b3-ab72-8278293863f6');

export const sendArtVectorEmail = (
  name,
  email,
  format,
  orderId,
  svgUrl,
  pngUrlTransparent,
  pngUrlOpaque
) => {
  // Don't send email in development
  if (!SEND_IN_DEV && process.env.NODE_ENV !== 'production') {
    return;
  }

  const Component =
github wildbit / postmark-cli / test / integration / shared.ts View on Github external
export const deleteTemplateData = async () => {
  const client = new postmark.ServerClient(serverToken);
  const templates = await client.getTemplates({count: 50});

  for (const template of templates.Templates) {
    if (template.Name.includes(templatePrefix)) {
      await client.deleteTemplate(template.TemplateId);
    }
  }
}
github wildbit / postmark-cli / src / commands / templates / pull.ts View on Github external
const fetchTemplateList = (options: TemplateListOptions) => {
  const { sourceServer, outputDir, requestHost } = options
  const spinner = ora('Pulling templates from Postmark...').start()
  const client = new ServerClient(sourceServer)
  if (requestHost !== undefined && requestHost !== '') {
    client.clientOptions.requestHost = requestHost
  }

  client
    .getTemplates()
    .then(response => {
      if (response.TotalCount === 0) {
        spinner.stop()
        log('There are no templates on this server.', { error: true })
        process.exit(1)
      } else {
        processTemplates({
          spinner,
          client,
          outputDir: outputDir,
github wildbit / postmark-cli / src / commands / email / raw.ts View on Github external
const sendCommand = (serverToken: string, args: RawEmailArguments): void => {
  const { from, to, subject, html, text, requestHost } = args
  const command: CommandResponse = new CommandResponse()
  command.initResponse('Sending an email')
  const client = new ServerClient(serverToken)
  if (requestHost !== undefined && requestHost !== '') {
    client.clientOptions.requestHost = requestHost
  }

  sendEmail(client, from, to, subject, html, text)
    .then(response => {
      command.response(JSON.stringify(response))
    })
    .catch(error => {
      command.errorResponse(error)
    })
}
github wildbit / postmark-cli / src / commands / email / template.ts View on Github external
const sendCommand = (serverToken: string, args: TemplatedEmailArguments) => {
  const { id, alias, from, to, model, requestHost } = args
  const command: CommandResponse = new CommandResponse()
  command.initResponse('Sending an email')
  const client = new ServerClient(serverToken)
  if (requestHost !== undefined && requestHost !== '') {
    client.clientOptions.requestHost = requestHost
  }

  sendEmailWithTemplate(client, id, alias, from, to, model)
    .then((response: any) => {
      command.response(JSON.stringify(response))
    })
    .catch((error: any) => {
      command.errorResponse(error)
    })
}

postmark

Official Node.js client library for the Postmark HTTP API - https://www.postmarkapp.com

MIT
Latest version published 3 months ago

Package Health Score

82 / 100
Full package analysis