Last active
January 7, 2019 15:31
-
-
Save Hydrock/f070a273d0987f2218871f3af4af2743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nodemailer = require('nodemailer'); | |
// HTML контент письма | |
const output = ` | |
<p>Срочно регистрируйся! 🤓</p> | |
`; | |
// Опции отправки почты | |
let mailOptions = { | |
from: '[email protected]', // почта отправителя | |
to: '[email protected]', // лист адресов получателей через запятую | |
subject: 'Срочное оповещение', // Заголовок письма | |
text: 'Срочно регистрируйся! 😨', // Текст письма если нет тела письма в html | |
html: output // html тело письма | |
}; | |
// Отправляет письмо | |
function sendMail(mailOptions) { | |
// Создаем обьект транспортера | |
// Авторизируемся | |
let smtpTransport; | |
try { | |
smtpTransport = nodemailer.createTransport({ | |
host: 'smtp.yandex.ru', | |
port: 465, | |
secure: true, // true для 465, false для других портов 587 | |
auth: { | |
user: "[email protected]", // почта пользователя для авторизации | |
pass: "secretPassword" // пароль пользователя | |
} | |
}); | |
} catch (e) { | |
return console.log('Ошибка: ' + e.name + ":" + e.message); | |
} | |
// Отправляем письмо | |
smtpTransport.sendMail(mailOptions, (error, info) => { | |
if (error) { | |
return console.log('Ошибка'); | |
} else { | |
console.log('Сообщение отправлено: %s', info.messageId); | |
} | |
}); | |
} | |
sendMail(mailOptions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment