我无法向邮件发送电子邮件

问题描述 投票:-1回答:2

我无法发送电子邮件给。注册时,您必须发送一封信给邮件进行确认。

我收到一个错误:Callback must be a function at maybeCallback

            const fs = require('fs');
            const path = require('path');

            let path_file = path.join(__dirname, '/views/email_templates/confirm_email.html');
            let html_file = await fs.readFile(path_file, { encoding: 'utf-8' });
            let html = await html_file(path_file);
            let template = handlebars.compile(html);
            let replacements = {
                target_link: link,
                password: merchant_password,
            };
            let htmlToSend = template(replacements);
            let mailOptions = {
                from: config.transport.user,
                to : merchant_email,
                subject : 'Please confirm your Email account and login password',
                html : htmlToSend,
            };
            smtpTransport.sendMail(mailOptions);

我的错是什么?

(node:14300) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
    at maybeCallback (fs.js:128:9)
    at Object.readFile (fs.js:277:14)
    at readFile (C:\Users\User\Documents\backend\src\controllers/merchants.js:299:38)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:14300) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async
function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14300) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
javascript node.js
2个回答
1
投票

fs.readFileSync(...)

尝试使用同步方式读取文件。


1
投票

错误非常清楚。你必须传递回调函数发送方法

smtpTransport.sendMail(mailOptions, function (error, info) {
        if (error) {
            console.log('error occurred while sending');
            console.log(error);
            return;
        }
        console.log('Message sent:');
});
© www.soinside.com 2019 - 2024. All rights reserved.