繁体   English   中英

我无法通过电子邮件发送电子邮件

[英]I can not send an email to the mail

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

我收到一个错误: 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.

错误非常明显。 您必须通过回调函数来发送方法

smtpTransport.sendMail(mailOptions, function (error, info) {
        if (error) {
            console.log('error occurred while sending');
            console.log(error);
            return;
        }
        console.log('Message sent:');
});

fs.readFileSync(...)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM