Send email using Gmail in Sheetbase backend app.
Git repo: https://github.com/sheetbase/gmail/
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"
});
string
Manage email from different account.
string
Sheetbase
.For better management, all email subject will be prefix with a string and labeled prefix:category
.
object
{ 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
}
}
}
object
{}
.List of supported templates.
{
templates: {
hello: (data: any) => `Hello ${data.name}!`,
}
}
Interface for sending email.
quota
: view remaining daily quota.send
: send email.View remaining daily quota.
const { remainingDailyQuota } = Gmail.quota();
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
);
To add routes to your app, see options AddonRoutesOptions:
Gmail.registerRoutes(options?: AddonRoutesOptions);
Disabled routes by default, to enable set { disabledRoutes: [] }
in registerRoutes()
:
[
"post:/mail" // send email
];
/mail
Get quota
.
/mail
Send email. Route body:
mailingData
: mail datacategory
: category nametemplate
: template configsilent
: override category silentSend 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,
}