How to use the Gmail Plugin
🚀 Easily send, read, and organize your emails using the Gmail API. 👉 Ensure you to install and terminate the Gmail plugin
//exec:node
const sender = "[YOUR-MAIL]@gmail.com";
const recipient = "[RECIPIENT]@gmail.com";
const subject = "🤘 Hello there!";
const content = `
Ok, this is just a message to say hello.
So... <b>Hello!</b> 🤘❤️😎 Thanks!
`;
sendMailWithGmail(sender, recipient, subject, content);
print("✅ Email sent successfully!");
//exec:node
const google = await getGoogleClient();
const gmail = google.gmail({ version: 'v1' });
const res = await gmail.users.messages.list({
userId: 'me',
labelIds: ['UNREAD', 'CATEGORY_PERSONAL', 'INBOX'],
maxResults: 10
});
if (res.data.messages) {
for (const message of res.data.messages) {
const msg = await gmail.users.messages.get({
userId: 'me',
id: message.id
});
const mail = readGmailMail(msg.data);
printJSON(mail);
}
} else {
print("✅ No unread emails found.");
}
//exec:node
const labelsToCreate = [
"Newsletter", "Order", "Shipping", "Public Event", "Personal Event",
"Personal", "Advertising", "Other"
];
const labels = await createAndGetLabels(labelsToCreate);
print("✅ Labels created successfully:", labels);
//exec:node
const google = await getGoogleClient();
const gmail = google.gmail({ version: 'v1' });
const content = `
This is a draft message.
<b>Hello!</b> 🤘❤️😎 Thanks!
`;
const encodedMessage = await createGmailMessage("[YOUR-MAIL]", "[RECIPIENT]", "Draft Subject", content);
const res = await gmail.users.drafts.create({
userId: 'me',
resource: {
message: {
// threadId: "193b0ff2813cxc0d", // <-- Uncomment to reply within an existing conversation
raw: encodedMessage
}
}
});
print("✅ Draft created successfully!");
🔍 More info: Gmail API Documentation ✅ You're now ready to manage Gmail emails directly from Znote! 🚀