Node-imap发送电子邮件但未将其保存到已发送

Kerim092

最近一直在使用node-imap并尝试实现发送电子邮件。这是feathers / node上的代码:

  create(data, params) {

    return new Promise((resolve, reject) => {


      // create reusable transporter object using the default SMTP transport
      let transporter = nodemailer.createTransport({
        host: this.host,
        port: this.smtpPort,
        secure: false, // true for 465, false for other ports,
        tls: {
          rejectUnauthorized: false
        },
        auth: {
          user: this.emailUsername, // generated ethereal user
          pass: this.emailPassword // generated ethereal password
        }
      });

      // setup email data with unicode symbols
      let mailOptions = {
        from: this.emailUsername, // sender address
        to: data.to, // list of receivers
        subject: data.subject, // Subject line
        text: data.body, // plain text body
        html: data.body // html body
      };

      // send mail with defined transport object
      transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
          reject(error);
          //console.log(error);
        }
        //console.log('Message sent: %s', info.messageId);
        return resolve(info);
      });

    });
  }

这段代码可以正常运行并按需发送电子邮件,但是在完成其工作后,我无法在“已发送”框中找到这些电子邮件...经验丰富的node-imap的人,我想念什么?干杯。

编辑::刚刚意识到它确实为某些电子邮件提供商(Gmail,Hotmail)保存了它,但对于另一些电子邮件提供商却没有。因此,我想我不会丢失任何东西……但是我如何手动将其保存给其他没有自动执行的提供者。

Kerim092

看来问题出在电子邮件提供商上,原因是此代码对Gmail或Hotmail来说效果很好...所以我所做的是在已为特定电子邮件提供商发送了电子邮件之后,将电子邮件手动附加到“已发送”框中...这是代码(如果有)1需要:

        // send mail with defined transport object
        transporter.sendMail(mailOptions, (error, info) => {
          if (error) {
            reject(error);
            //console.log(error);
          }

          if (checkEmail(userEmail) == 'linksoft') {
            imap.once('ready', function () {
              imap.openBox('inbox.Sent', false, (err, box) => {
                if (err) throw err;

                let msg, htmlEntity, plainEntity;
                msg = mimemessage.factory({
                  contentType: 'multipart/alternate',
                  body: []
                });
                htmlEntity = mimemessage.factory({
                  contentType: 'text/html;charset=utf-8',
                  body: mailOptions.html
                });
                plainEntity = mimemessage.factory({
                  body: mailOptions.text
                });
                msg.header('Message-ID', '<1234qwerty>');
                msg.header('From', mailOptions.from);
                msg.header('To', mailOptions.to);
                msg.header('Subject', mailOptions.subject);
                msg.header('Date', new Date()));
                //msg.body.push(htmlEntity);
                msg.body.push(plainEntity);

                imap.append(msg.toString());

              })
            });

            imap.once('error', function (err) {
              reject(err);
            });

            imap.once('end', function () {
              resolve(response);
            });

            imap.connect();
          }
          //console.log('Message sent: %s', info.messageId);
          return resolve(info);
        });

相关性:mimemessage模块,用于在将其存储到“已发送”框中之前生成mime消息,因为imap.append()需要mime消息类型

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法使用MailGun Node API发送电子邮件

通过node -red发送电子邮件

如何从Node.js发送电子邮件?

在Node.js中发送电子邮件?

无法使用 Node-RED 发送电子邮件

使用Node.js中的Azure SendGrid发送电子邮件

使用sendgrid发送电子邮件时在Node.js中禁止403

发送电子邮件时,Node.Js AWS SES-ETIMEDOUT

如何在Node.Js中将角度组件呈现为HTML(发送电子邮件)

node.js nodemailer和nodemailer-sendinblue-transport无法发送电子邮件

Node.JS:即使没有错误,Nodemailer 也不发送电子邮件

我正在尝试使用 node、nodemon、express 和 dotenv 发送电子邮件

使用nodemailer通过Node.js发送电子邮件不起作用

Node Webkit-通过Outlook打开和发送电子邮件

无法通过node.js中的nodemailer发送电子邮件

为什么我不能通过Node上的Amazon ses发送电子邮件?

使用Amazon SES服务从node.js发送电子邮件不起作用

尽管返回“成功”响应,但node.js上的SES不发送电子邮件

我如何使用node和sendgrid发送电子邮件,包括链接?

从Node.js中的sendGrid发送电子邮件时出现“ UnhandledPromiseRejectionWarning:错误:禁止”

使用 Node.js 处理程序发送和发送电子邮件时出现 AWS Lambda NetworkingError

TypeError:在node.js中使用aws-sdk发送电子邮件时,密钥必须是缓冲区

如何在Node.js中使用我的服务器域发送电子邮件

如果满足条件,请更新收集并发送电子邮件|| Mongo Node.js

我想在node js中使用nodemailer发送电子邮件附件。我正在使用elasticemail gate方式

为什么发送电子邮件时 sendgrid node.js api 会挂起并且没有错误?

是否可以在没有node.js的情况下使用react-native发送电子邮件?

Node.js通过电子邮件发送流

使用 Node JS 发送免费电子邮件