Gmail alarm
Send administrator alerts from the site owner's Google account to the same Gmail account.
Link Gmail sending permissions
- Open the Gmail Settings tab in your site's Settings.
- Tap Connect to Gmail and only have Gmail sending permissions on the Google official screen. Allowed.
- Cake20 login permissions and Gmail sending permissions are separate. Gmail alarm Only the site owner using it makes one additional connection.
- Gmail connections are stored in a Cake20 user account, allowing multiple connections held by the same user. Share it on the site. You can choose whether or not to activate each site separately.
- Select Enable Gmail Alerts, save your settings, and then restart the website.
- Automatically sends an alarm when site ownership is transferred or Gmail is disconnected. Disable.
Cake20 does not read or search Gmail messages. gmail.send sending permission and We only use encrypted Refresh Tokens and do not accept Google passwords.
Send email to administrator
- Gmail is only used in server code such as API, Route, Middleware, Task, and Job.
- gmail.active means the site setting is active and the current owner has Gmail permissions. True when connected.
- gmail.send requires subject and text, html is optional.
- Subject can be between 1 and 200 characters, text can be between 1 and 50,000 characters, and HTML can be up to 200,000 characters.
- The result contains Gmail messageId and threadId.
- The sender and recipient are locked to the current site owner's linked Gmail. No to, from, or OAuth Token arguments are provided.
// server/api/order.post.ts
export default async () => {
// Notify site owner after saving order
if (gmail.active) {
await gmail.send({
subject: "A new order has been received.",
text: "Please check order number #1024.",
html: "<h2>New order</h2><p>Order number <strong>#1024</strong></p>"
});
}
return { ok: true };
};Reusable Email Templates
- The official Gmail administrator alert template (gmail-alert) is a site user login Provides only one button, Google, and sends the logged in user's request to the owner's Gmail. This is an example to convey.
- The template's Google User Login OAuth and the Site Owner's Gmail Send OAuth are These are different permissions. User login alone does not activate gmail.send.
- When inserting user input into HTML, it must be HTML escaped.
- If an alarm failure should not cancel order/inquiry storage, set a try/catch policy. Define clearly.
- It is up to the site owner to decide which event to send: login, comment, order, inquiry or error. Select this and Cake20 will not randomly add default alarms.
// server/utils/owner-alert.ts
type AlertInput = {
title: string;
summary: string;
action: string;
};
export function ownerAlert(input: AlertInput) {
return {
subject: `[${project.title}] ${input.title}`,
text: `${input.summary}\n\nView: ${input.action}`,
html: `
<div style="font-family:Arial,sans-serif;line-height:1.6">
<h2>${input.title}</h2>
<p>${input.summary}</p>
<p><a href="${input.action}">Check it out on the site</a></p>
</div>
`
};
}
// server/api/inquiry.post.ts
export default async () => {
if (gmail.active) {
await gmail.send(ownerAlert({
title: "A new inquiry has been registered.",
summary: "There is a new inquiry that requires administrator confirmation.",
action: `${app.url}/admin/inquiries`
}));
}
return { ok: true };
};When gmail.send is executed in the editor's API, Task, or Job test, it is sent to the actual Gmail. It is sent. Notify the site owner before repeat testing.