Welcome to the @elara-services/mailer
package!
This package allows you to send an SMS message or email via a Gmail account!
Getting Started
- You need to get the clientId, clientSecret and refreshToken from your Google Cloud Platform account: Guide here
- MAKE SURE TO ENABLE THE
GMAIL API
SERVICE ON YOUR GOOGLE CLOUD ACCOUNT!
const { Mailer } = require("@elara-services/mailer");
const mail = new Mailer("example@gmail.com", {
username: `Elara Services: Mailer`,
clientId: "Your google apis client ID",
clientSecret: "Your google apis client secret",
refreshToken: "Your gmail refresh token",
});
Send SMS:
mail.phone("PHONE_NUMBER", "Text message here");
Send Email(s):
mail.email("boop@example.com", {
text: `Boop!`,
subject: `Henlo!`,
html: `<html><body><h1>Beep!</h1></body></html>`,
});
mail.email([
"foo@example.com",
"bar@example.com",
"...etc"
], {
text: `Boop!`,
subject: `Henlo!`,
html: `<html><body><h1>Beep!</h1></body></html>`,
});
Server API
Getting Started
const { Server } = require("@elara-services/mailer");
const server = new Server({
email: "your_gmail_account@gmail.com",
options: {
username: "Elara Services: Mailer",
clientId: "your_client_id",
clientSecret: "your_client_secret",
refreshToken: "your_refresh_token",
}
}, "API_KEY_HERE", 2020);
server.start();
Authorization:
- You need the
Authorization
header for all routes. (If you have the API key provided)
Send Endpoints:
Route: /email
Body:
{
"email": "xxx",
"subject": "Email Subject (OPTIONAL)",
"text": "Text for the email",
"html": "HTML code for the email (Use 'html' or 'text')"
}
Route: /sms
Body:
{
"phone": "xxx",
"text": "Text for the message"
}
Verification Endpoints:
Route: /verify/sms
Body:
{
"phone": "123456789",
"codeLength": 20,
}
Route: /verify/email
Body:
{
"email": "xxxx",
"codeLength": 20,
}
Verification Responses:
Success:
{
"status": true,
"code": "xxx"
}
Fail:
{
"status": false,
"message": "xxx"
}