const nodemailer = require('nodemailer');
const directTransport = require('nodemailer-direct-transport');
const fromHost = `mysite.com`;
const from = 'site' + '@' + "gmail.com";
console.log('Email will be sent from:');
console.log(from, '\n');
// Ask for email address
const to = prompt('Enter your email address ').trim();
// Генерируем код
const trueVerificationCode = Math.round(Math.random() * (10e5 - 1)).toString();
const transport = nodemailer.createTransport(directTransport({
name: fromHost
}));
let y = trueVerificationCode;
// Отправляем письмо
transport.sendMail({
from, to,
subject: 'Verify your email address',
html: `
<div style="width:100%;display:flex;flex-direction:column;justify-content:center;
align-items:center;background:lightblue;padding:50px;box-sizing:border-box;">
<h1>Verify your email address</h1>
<p>Site has tried to verify your email address "${to}".
If this wasn't you, ignore and delete this email. Otherwise, the verification code is bellow:</p>
<div style="padding:50px;background:lightgray;border-radius:10px;font-size:30px;
font-family:monospace;">${trueVerificationCode}</div></div>
`
}, (err, data) => {
if (err) {
console.error('There was an error:', err);
} else {
console.log('\nVerification email sent, check your inbox\n');
const userVerificationCode = prompt('Enter your verification code ');
if (userVerificationCode == trueVerificationCode) {
console.log('Email address verified');
} else {
console.log('Code incorrect');
}
}
});
let tab = window.open("url");
let interval = setInterval(() => {
if (tab.closed) {
//Реализовуете выход когда вкладка закрыта
clearInterval(interval);
}
}, 200);
import chalk from 'chalk';
const nodemailer = require('nodemailer');
const directTransport = require('nodemailer-direct-transport');
const fromHost = `mail.my`;
const from = 'Mail' + '@' + fromHost; //придумываете свою почту(может быть несуществующая)
const to = prompt('Кому отправить: ').trim();
const transport = nodemailer.createTransport(directTransport({
name: fromHost
}));
transport.sendMail({
from, to,
subject: 'Заголовок письма',
html: `
<h1>Ваше письмо</h1>
`
}, (err, data) => {
if (err) {
console.error('Ошибка при отправке:', err);
} else {
console.log('Письмо отправлено');
}
});
const express = require('express');
const app = express();
exports.app = app;
const http = require('http');
const server = http.createServer(app);
app.get("/hello", (req, res) => {
//либо перенапрвление на сайт:
res.redirect("https://....");
//либо отдать свою страницу(файл):
res.sendFile(__dirname + '/public/index.html');
//или отправить напрямую html-код:
res.send(`
<html>
<head>
<title>Server</title>
</head>
<body>
<h1>hello server</h1>
</body>
</html>
`);
})
server.listen(8080, () => {
//console.log("\x1B[32m%c started", 'color: pink; background: red;');
});
const { Server } = require('http');
const s = Server();
s.addListener('request', function (req, res) {
res.end('My first server!\n');
});
s.listen(4321);