@EmKotlety

Как отправить email c sendpulse smtp node?

вот ответ с ошибкой:
{
[0]     id: 300703,
[0]     name: 'My emails',
[0]     all_email_qty: 1,
[0]     active_email_qty: 1,
[0]     inactive_email_qty: 0,
[0]     new_phones_quantity: 0,
[0]     active_phones_quantity: 0,
[0]     exc_phones_quantity: 0,
[0]     creationdate: '2022-05-03 03:27:47',
[0]     status: 0,
[0]     status_explain: 'Active'
[0]   }
[0] ]
[0] { message: 'Sender is not valid', error_code: 422 }

Код:
let sendpulse = require("sendpulse-api");
module.exports = function sendMail() {
    const sendpulse = require('sendpulse-api');
    const SENDPULSE_USER_ID = '*****************************';
    const SENDPULSE_SECRET = '******************************';
    const API_USER_ID = SENDPULSE_USER_ID;
    const API_SECRET = SENDPULSE_SECRET;
    const SENDER_NAME = 'Tima';
    const EMAIL_FROM = 'izajcev997@gmail.com';
    const TOKEN_STORAGE =  "./tmp/";
    sendpulse.init(API_USER_ID,API_SECRET,TOKEN_STORAGE, function(token){
        function answerGetter(data){
            console.log(data);
        };
        let email = {
            "html" :  "<h1>Example text</h1>",
            "text" :"Example text",
            "subject" : "Example subject",
            "from" : {
                "name" : "Vasia",
                "email" : 'izajcev997@gmail.com'
            },
            "to" : [
                {
                    "name" : "triabogin@gmail.com",
                    "email" : "triabogin@gmail.com"
                },
            ],
            "bcc" : []
        };
        sendpulse.listAddressBooks(answerGetter);
        sendpulse.smtpSendMail(answerGetter,email);
    });

и в index.js вызываю его
app.get('/sendmail', (req, res, next)=>{
    sendMail()
    res.send('добрый вечер')
  })
Токен появляется в tmp
  • Вопрос задан
  • 269 просмотров
Пригласить эксперта
Ответы на вопрос 1
rama_jecboom
@rama_jecboom
Не знаю как их библиотека работает, но вот только что посмотрел, есть библиотека nodemailer2 . Её правда уже 5 лет не обновляют, но потестировал, всё хорошо работает. Просто бери у SENDPULSE smtp и вставляй его сюда.

var nodemailer = require('nodemailer2');
 
// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport('smtps://user%40gmail.com:pass@smtp.gmail.com');
 
// setup e-mail data with unicode symbols
var mailOptions = {
    from: 'fkdghkfmkgbfd@ya.ru', // sender address
    to: 'dfghgfhfd@mail.ru', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world ', // plaintext body
    html: '<b>Hello world </b>' // html body
};
 
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
    if(error){
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);
});
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы