官方电子邮件 JS SDK for Node.js
SDK 为 电子邮件JS.com 顾客.
使用您的电子邮件JS 账户发送邮件 .
免责声明
这是Node.js平台,否则使用
链接
介绍
电子邮件JS帮助您直接从一个命令的代码发送电子邮件. 不需要大的知识 – 只要将 EmailJS 连接到被支持的其中之一 电子邮件服务, 创建电子邮件模板, 并使用我们的 SDK 触发电子邮件.
使用量
使用 EmailJS SDK 安装电子邮件 无数字 :
$ npm install @emailjs/nodejs
说明:默认情况下,对于非浏览器应用程序,API请求被禁用. 你需要通过激活它们 账户:安全。 。 。 .
财务问题
非浏览器应用程序的 API 呼叫已禁用
您需要激活 API 请求 结束 账户:安全。 。 。 .
实例
ECMAScript 模块
使用定制的发送方法发送电子邮件
import emailjs from '@emailjs/nodejs';
const templateParams = {
name: 'James',
notes: 'Check this out!',
};
emailjs
.send('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', templateParams, {
publicKey: 'YOUR_PUBLIC_KEY',
privateKey: 'YOUR_PRIVATE_KEY', // optional, highly recommended for security reasons
})
.then(
(response) => {
console.log('SUCCESS!', response.status, response.text);
},
(err) => {
console.log('FAILED...', err);
},
);
输入( 可选)
import emailjs from '@emailjs/nodejs';
// set Public Key as global settings
emailjs.init({
publicKey: 'YOUR_PUBLIC_KEY',
privateKey: 'YOUR_PRIVATE_KEY', // optional, highly recommended for security reasons
});
emailjs.send('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID').then(
(response) => {
console.log('SUCCESS!', response.status, response.text);
},
(err) => {
console.log('FAILED...', err);
},
);
使用电子邮件JS 错误处理器等待/同步
import emailjs, { EmailJSResponseStatus } from '@emailjs/nodejs';
try {
await emailjs.send(
'YOUR_SERVICE_ID',
'YOUR_TEMPLATE_ID',
{},
{
publicKey: 'YOUR_PUBLIC_KEY',
privateKey: 'YOUR_PRIVATE_KEY', // optional, highly recommended for security reasons
},
);
console.log('SUCCESS!');
} catch (err) {
if (err instanceof EmailJSResponseStatus) {
console.log('EMAILJS FAILED...', err);
return;
}
console.log('ERROR', err);
}
配置
选项
可在全球范围内使用 输入 作为函数的第四个参数.
本地参数的优先级将高于全球参数.
| 名称 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 公钥 | 字符串 | 要求公用钥匙引用该方法. | |
| 块列表 | 块列表 | 块列表设置. | |
| 限制 | 限制 | 限制速率配置 . | |
| 存储器 | 存储器 | 自定义密钥值存储的提供者 . |
块列表
如果被监视的变量包含块列表中的值,则允许忽略一个方法调用.
如果请求被阻断, 该方法将返回错误 403 .
| 名称 | 类型 | 说明 |
|---|---|---|
| 列表 | 字符串 [] | 字符串阵列包含要阻断的值 . |
| 可变可见 | 字符串 | 被监视变量的名称 . |
限制
允许设定调用方法的限速率 .
如果请求达到极限速率,该方法会还原出错429.
| 名称 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 编号 | 字符串 | 页面路径 | 限制率默认为每页. 要推翻行为,请设定ID. 它可以是每个页面,组,或应用程序的自定义ID. |
| 节流阀 | 数目 | (单位:百万美元) 在数毫秒后, 允许下一个请求 . |
存储器
允许提供自定义密钥值存储 。 默认情况下,如果可用则使用本地Storage.
自定义提供者必须匹配接口.
interface StorageProvider {
get: (key: string) => Promise<string | null | undefined>;
set: (key: string, value: string) => Promise<void>;
remove: (key: string) => Promise<void>;
}
宣布全局设置
import emailjs from '@emailjs/nodejs';
emailjs.init({
publicKey: 'YOUR_PUBLIC_KEY',
privateKey: 'YOUR_PRIVATE_KEY', // optional, highly recommended for security reasons
blockList: {
list: ['[email protected]', '[email protected]'],
},
limitRate: {
throttle: 10000, // 10s
},
});
覆盖本地设置
import emailjs from '@emailjs/nodejs';
const templateParams = {
name: 'James',
notes: 'Check this out!',
};
emailjs
.send('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', templateParams, {
publicKey: 'YOUR_PUBLIC_KEY',
privateKey: 'YOUR_PRIVATE_KEY', // optional, highly recommended for security reasons
blockList: {
watchVariable: 'userEmail',
},
limitRate: {
throttle: 0, // turn off the limit rate for these requests
},
})
.then(
(response) => {
console.log('SUCCESS!', response.status, response.text);
},
(err) => {
console.log('FAILED...', err);
},
);