JSPM

@sheetbase/gmail-server

0.0.8
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q41349F
  • License MIT

Send email using Gmail in Sheetbase backend app.

Package Exports

  • @sheetbase/gmail-server

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sheetbase/gmail-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Sheetbase Module: @sheetbase/gmail-server

Send email using Gmail in Sheetbase backend app.

Build Status Coverage Status NPM License clasp Support me on Patreon PayPal Ask me anything

Install

Using npm: npm install --save @sheetbase/gmail-server

import * as Gmail from "@sheetbase/gmail-server";

As a library: 1cKQyLf_OZwivLAiNBw-naLV_uq-lmf8AcOEnE9t5E9IQhA1Fo8JTV_sm

Set the Indentifier to GmailModule and select the lastest version, view code.

declare const GmailModule: { Gmail: any };
const Gmail = GmailModule.Gmail;

Usage

Getting started

Install: npm install --save @sheetbase/gmail-server

Usage:

import { gmail } from "@sheetbase/gmail-server";

const Gmail = gmail(
  /* options */ {
    prefix: "MyApp"
  }
);

const { threadId } = Gmail.send({
  recipient: "xxx@xxx.xxx"
});

Configs

forwarding

  • Type: string
  • Default: current account email.

Manage email from different account.

prefix

  • Type: string
  • Default: Sheetbase.

For better management, all email subject will be prefix with a string and labeled prefix:category.

categories

  • Type: object
  • Default: an uncategoriezed category: { uncategorized: { title: 'Uncategorized', silent: true } }.

List of support categories, all email will be sorted to one of these categories.

{
  categories: {
    message: 'Messages',
    misc: {
      title: 'Misc',
      silent: true
    }
  }
}

templates

  • Type: object
  • Default: {}.

List of supported templates.

{
  templates: {
    hello: (data: any) => `Hello ${data.name}!`,
  }
}

Gmail

Interface for sending email.

  • quota: view remaining daily quota.
  • send: send email.

quota

View remaining daily quota.

const { remainingDailyQuota } = Gmail.quota();

send

Send email.

// To: xxx@xxx.xxx
// Subject: Send me email
// Content: Hello world!
// Label: <prefix>:Uncategorized
const { threadId } = Gmail.send({
  recipient: "xxx@xxx.xxx",
  subject: "Send me email",
  options: {
    htmlBody: `<p>Hello world!</p>`
  }
});

// To: ...
// Subject: ...
// Content: ...
// Label: <prefix>:Messages
Gmail.send(
  {
    /* ... */
  },
  "message"
);

// To: ...
// Subject: ...
// Content: Hello John!
// Label: ...
Gmail.send(
  {
    recipient: "xxx@xxx.xxx",
    subject: "Send me email"
  },
  "message",
  {
    hello: { name: "John" }
  }
);

// force silent = false
Gmail.send(
  {
    /* ... */
  },
  null,
  null,
  false
);

Routes

To add routes to your app, see options AddonRoutesOptions:

Gmail.registerRoutes(options?: AddonRoutesOptions);

Default disabled

Disabled routes by default, to enable set { disabledRoutes: [] } in registerRoutes():

[
  "post:/mail" // send email
];

Endpoints

GET /mail

Get quota.

POST /mail

Send email. Route body:

  • mailingData: mail data
  • category: category name
  • template: template config
  • silent: override category silent

Send an email:

{
  mailingData: {
    recipient: 'xxx@xxx.xxx',
    subject: 'Send me email',
    options: {
      htmlBody: `<p>Hello world!</p>`,
    }
  }
}

With category:

{
  mailingData: { /*  */ },
  category: 'message'
}

With template:

{
  mailingData: { /*  */ },
  template: {
    hello: { name: 'John' }
  }
}

Override category silent:

{
  mailingData: { /*  */ },
  silent: false,
}

Examples

import * as Gmail from "./public_api";

function load_() {
  return Gmail.gmail();
}

License

@sheetbase/gmail-server is released under the MIT license.