@brojs/mailer
v2.0.0
Published
mailer helper
Readme
@brojs/mailer
Пакет для работы с email в проектах BroJS.
Установка
npm install @brojs/mailerИспользование
Базовая настройка
import { Mailer } from '@brojs/mailer';
const mailer = new Mailer({
host: 'smtp.example.com',
port: 587,
secure: false,
auth: {
user: '[email protected]',
pass: 'password'
}
});Отправка email
await mailer.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email',
text: 'This is a test email',
html: '<p>This is a test email</p>'
});Отправка с шаблоном
await mailer.sendTemplate({
template: 'welcome',
to: '[email protected]',
data: {
name: 'John',
activationLink: 'https://example.com/activate'
}
});Конфигурация
Основные опции
host- SMTP серверport- Порт SMTP сервераsecure- Использование SSL/TLSauth- Данные аутентификации
Дополнительные опции
templates- Путь к шаблонам писемdefaultFrom- Адрес отправителя по умолчаниюreplyTo- Адрес для ответаpool- Использование пула соединений
Шаблоны писем
Структура шаблона
<!-- templates/welcome.html -->
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome, {{name}}!</h1>
<p>Please activate your account by clicking the link below:</p>
<a href="{{activationLink}}">Activate Account</a>
</body>
</html>Использование шаблонов
await mailer.sendTemplate({
template: 'welcome',
to: '[email protected]',
data: {
name: 'John',
activationLink: 'https://example.com/activate'
}
});Разработка
npm testЛицензия
MIT
