Update files
This commit is contained in:
parent
9ebdd81c48
commit
b59c5afe51
|
|
@ -2,8 +2,9 @@ const AWS = require('aws-sdk');
|
|||
const nodemailer = require('nodemailer');
|
||||
const config = require('../config');
|
||||
|
||||
// Инициализация AWS SES
|
||||
// Инициализация AWS SES / SESv2
|
||||
let sesClient = null;
|
||||
let sesv2Client = null;
|
||||
let transporter = null;
|
||||
|
||||
const initializeEmailService = () => {
|
||||
|
|
@ -29,16 +30,19 @@ const initializeEmailService = () => {
|
|||
region: awsRegion
|
||||
};
|
||||
|
||||
// Для Yandex Cloud Postbox нужен кастомный endpoint
|
||||
// Для Yandex Cloud Postbox нужен кастомный endpoint и SESv2 API
|
||||
if (endpointUrl) {
|
||||
sesConfig.endpoint = endpointUrl;
|
||||
console.log(`[Email] Используется Yandex Cloud Postbox с endpoint: ${endpointUrl}`);
|
||||
// Yandex Cloud Postbox использует SESv2 API
|
||||
sesv2Client = new AWS.SESv2(sesConfig);
|
||||
} else if (!validAWSRegions.includes(awsRegion)) {
|
||||
console.warn(`[Email] Невалидный регион AWS SES: ${awsRegion}. Используется us-east-1`);
|
||||
sesConfig.region = 'us-east-1';
|
||||
}
|
||||
|
||||
sesClient = new AWS.SES(sesConfig);
|
||||
} else {
|
||||
sesClient = new AWS.SES(sesConfig);
|
||||
}
|
||||
} else if (emailProvider === 'yandex' || emailProvider === 'smtp') {
|
||||
const emailConfig = config.email?.[emailProvider] || config.email?.smtp || {};
|
||||
|
||||
|
|
@ -90,8 +94,39 @@ const sendEmail = async (to, subject, html, text) => {
|
|||
const emailProvider = process.env.EMAIL_PROVIDER || 'aws';
|
||||
const fromEmail = process.env.EMAIL_FROM || config.email?.from || 'noreply@nakama.guru';
|
||||
|
||||
if (emailProvider === 'aws' && sesClient) {
|
||||
// Отправка через AWS SES
|
||||
// Использовать SESv2 для Yandex Cloud Postbox, SES для обычного AWS
|
||||
if (emailProvider === 'aws' && (sesClient || sesv2Client)) {
|
||||
if (sesv2Client) {
|
||||
// Отправка через AWS SESv2 (Yandex Cloud Postbox)
|
||||
const params = {
|
||||
FromEmailAddress: fromEmail,
|
||||
Destination: {
|
||||
ToAddresses: [to]
|
||||
},
|
||||
Content: {
|
||||
Simple: {
|
||||
Subject: {
|
||||
Data: subject,
|
||||
Charset: 'UTF-8'
|
||||
},
|
||||
Body: {
|
||||
Html: {
|
||||
Data: html,
|
||||
Charset: 'UTF-8'
|
||||
},
|
||||
Text: {
|
||||
Data: text || html.replace(/<[^>]*>/g, ''),
|
||||
Charset: 'UTF-8'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await sesv2Client.sendEmail(params).promise();
|
||||
return { success: true, messageId: result.MessageId };
|
||||
} else if (sesClient) {
|
||||
// Отправка через AWS SES (обычный AWS)
|
||||
const params = {
|
||||
Source: fromEmail,
|
||||
Destination: {
|
||||
|
|
@ -117,6 +152,7 @@ const sendEmail = async (to, subject, html, text) => {
|
|||
|
||||
const result = await sesClient.sendEmail(params).promise();
|
||||
return { success: true, messageId: result.MessageId };
|
||||
}
|
||||
} else if (transporter) {
|
||||
// Отправка через SMTP (Yandex, Gmail и т.д.)
|
||||
const info = await transporter.sendMail({
|
||||
|
|
|
|||
Loading…
Reference in New Issue