简体   繁体   English

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

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

I can't send email to. 我无法发送电子邮件到。 When registering, you must send a letter to the mail to confirm it. 注册时,您必须向邮件发送一封信件以进行确认。

I get an error: Callback must be a function at maybeCallback 我收到一个错误: 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);

What's my mistake? 我怎么了

(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.

Error is pretty much clear. 错误非常明显。 you must pass callback function to send method 您必须通过回调函数来发送方法

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.

相关问题 如何在不打开邮件客户端的情况下使用 JavaScript 发送电子邮件? - How do I send email with JavaScript without opening the mail client? 我可以使用javascript发送电子邮件吗 - Can I send email using javascript 从Bootstrap框架发送电子邮件我的错误是我收到消息是邮件发送成功,但是我没有收到任何邮件 - send email from bootstrap framework My error in this is i got a message is Mail sent successfully but i didn't receive any mail 如何连接到默认邮件客户端并发送附件? - How can I connect to Default mail Client and send an attachment? 我怎样才能将表单数据作为邮件发送并仍然提交 - How can i Send form data as mail and still submit 发送带有rails 4,邮件表单和ajax的电子邮件? - Send email with rails 4, mail form, and ajax? 为什么邮件没有发送到提及的电子邮件ID? - why mail is not send to email id as mention? 是否可以仅使用Javascript发送电子邮件而不必单击电子邮件客户端上的“发送”按钮? - Can I Send an Email using ONLY Javascript Without Having to Click The Send Button on the Email Client? 我可以使用HTML5发送客户端电子邮件吗? - Can I use HTML5 to send a client-side email? 我无法通过谷歌脚本发送带有 pdf 作为附件的电子邮件 - I can't send an email with pdf as attachment by google script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM