diff --git a/README.md b/README.md
index 2ece210..5b9b6dd 100644
--- a/README.md
+++ b/README.md
@@ -11,4 +11,6 @@ SESSION_SECRET=secret
DATABASE_URI=подключение к БД MONGODB
DATABASE_NAME=имя БД
QIWI_SECRET_KEY=секретный ключ QIWI API
+EMAIL_LOGIN=логин от почты
+EMAIL_PASSWORD=пароль от почты
```
\ No newline at end of file
diff --git a/config/nodemailer.config.js b/config/nodemailer.config.js
new file mode 100644
index 0000000..c0e80b6
--- /dev/null
+++ b/config/nodemailer.config.js
@@ -0,0 +1,13 @@
+const nodemailer = require('nodemailer');
+
+module.exports = {
+ transporter: nodemailer.createTransport({
+ host: "smtp.mail.ru",
+ port: 465,
+ secure: true, // true for 465, false for other ports
+ auth: {
+ user: process.env.EMAIL_LOGIN, // email login
+ pass: process.env.EMAIL_PASSWORD // email password
+ }
+ })
+}
\ No newline at end of file
diff --git a/config/routes/success.js b/config/routes/success.js
index 422a153..83a8b07 100644
--- a/config/routes/success.js
+++ b/config/routes/success.js
@@ -1,4 +1,5 @@
const ObjectID = require('mongodb').ObjectID;
+const nodemailer = require('../nodemailer.config');
module.exports = function(server, db, qiwiApi) {
server.get('/success', (req, res) => {
@@ -15,13 +16,13 @@ module.exports = function(server, db, qiwiApi) {
amount = parseFloat(data.amount.value);
if (status === 'PAID') {
- const ids = query.item_id.split('and');
- const findBill = await db.collection('buyers').findOne({bill_id: query.bill_id});
+ const ids = query.item_id.split('and'),
+ findBill = await db.collection('buyers').findOne({bill_id: query.bill_id});
if(findBill == null) {
const result = [];
- //выдаем данные и создаем покупателя
+ // создаем покупателя и выдаем данные
for (let i = 0; i < ids.length; i++) {
const item = await db.collection('info').findOne({"_id": ObjectID(ids[i])}),
data = item.data;
@@ -29,8 +30,19 @@ module.exports = function(server, db, qiwiApi) {
result.push(data.splice(-1, 1).join(''));
db.collection('info').updateOne({"_id": ObjectID(ids[i])}, {$set: {data: data}});
}
-
db.collection('buyers').insertOne({bill_id, email, method, date, amount, data: result});
+
+ await nodemailer.transporter.sendMail({
+ from: `"Оплата аккаунта." <${process.env.EMAIL_LOGIN}>`, // sender address
+ to: email, // list of receivers
+ subject: "Оплата успешно проведена.", // subject
+ text: "Данные купленного товара находятся в этом письме.", // plain text body
+ html: `Номер заказа: ${bill_id}
+ Данные товара:
+
${result.join('
')}