docs

Gmail Server

Send email using Gmail in Sheetbase backend app.

Git repo: https://github.com/sheetbase/gmail/

Getting started

Install: npm install --save @sheetbase/gmail

Usage:

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

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

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

Configs

forwarding

Manage email from different account.

prefix

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

categories

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

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

templates

List of supported templates.

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

Gmail

Interface for sending 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:

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,
}