Send email using Gmail in Sheetbase backend app.
npm install @sheetbase/gmail-servernpm install --save @sheetbase/gmail-server
ts
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.
`ts
declare const GmailModule: { Gmail: any };
const Gmail = GmailModule.Gmail;
`
Usage
- Docs homepage: https://sheetbase.github.io/gmail-server
- API reference: https://sheetbase.github.io/gmail-server/api
Getting started
Install: npm install --save @sheetbase/gmail-server
Usage:
`ts
import { gmail } from "@sheetbase/gmail-server";
const Gmail = gmail(
/ options / {
prefix: "MyApp"
}
);
const { threadId } = Gmail.send({
recipient: "xxx@xxx.xxx"
});
`
Configs
$3
- Type: string
- Default: current account email.
Manage email from different account.
$3
- Type: string
- Default: Sheetbase.
For better management, all email subject will be prefix with a string and labeled prefix:category.
$3
- 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.
`ts
{
categories: {
message: 'Messages',
misc: {
title: 'Misc',
silent: true
}
}
}
`
$3
- Type: object
- Default: {}.
List of supported templates.
`ts
{
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.
`ts
const { remainingDailyQuota } = Gmail.quota();
`
send
Send email.
`ts
// To: xxx@xxx.xxx
// Subject: Send me email
// Content: Hello world!
// Label: :Uncategorized
const { threadId } = Gmail.send({
recipient: "xxx@xxx.xxx",
subject: "Send me email",
options: {
htmlBody: Hello world!
}
});
// To: ...
// Subject: ...
// Content: ...
// Label: :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
);
`
$3
To add routes to your app, see options AddonRoutesOptions:
`ts
Gmail.registerRoutes(options?: AddonRoutesOptions);
`
#### Default disabled
Disabled routes by default, to enable set { disabledRoutes: [] } in registerRoutes():
`ts
[
"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:
`ts
{
mailingData: {
recipient: 'xxx@xxx.xxx',
subject: 'Send me email',
options: {
htmlBody: Hello world!
,
}
}
}
`
With category:
`ts
{
mailingData: { / / },
category: 'message'
}
`
With template:
`ts
{
mailingData: { / / },
template: {
hello: { name: 'John' }
}
}
`
Override category silent:
`ts
{
mailingData: { / / },
silent: false,
}
`
$3
`ts
import * as Gmail from "./public_api";
function load_() {
return Gmail.gmail();
}
``