【问题标题】:NodeJs fails to send email with gmail smtpNodeJs 无法使用 gmail smtp 发送电子邮件
【发布时间】:2021-07-06 14:46:40
【问题描述】:

看了一些帖子后,我不知道为什么这个流星代码无法将电子邮件发送到我自己的电子邮件地址。任何想法都非常感谢。

//server.main.js

import { Email } from 'meteor/email'

smtp = {
  username: 'my@gmail.com',
  password: 'pass',
  server: 'smtp.gmail.com',
  port: '465'
};

process.env.MAIL_URL = 'smtp://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password) + '@' + encodeURIComponent(smtp.server) + ':' + smtp.port;

//then inside a method call
Testimonies.insert(testamonyObj, function(err, res) {
      if (!err) {
        let add = 'myAdd@gmail.com'
        let mess = 'alosh bel awee'
        Email.send({ add, add, res, mess });
      }

【问题讨论】:

    标签: javascript node.js meteor


    【解决方案1】:

    您的代码乍一看还不错。您需要在您的 gmail 帐户中允许安全性较低的应用程序。

    您可以在此处阅读更多信息:https://support.google.com/accounts/answer/6010255?hl=en

    【讨论】:

    • 是的。我必须执行此步骤,这使我可以在使用接受的答案后进行修复。谢谢
    【解决方案2】:

    好吧,您传递给Email.send 的选项对象只是不包含必要的字段,尤其是to 字段,请参阅 https://docs.meteor.com/api/email.html#Email-send。您当前的对象仅包含三个字段addresmess,它们都不是send 函数可以理解的有效字段名称。

    试试这个:

    Email.send({ 
      to: add,
      from: add,
      subject: res,
      text: mess
    });
    

    【讨论】:

      猜你喜欢
      • 2020-05-30
      • 1970-01-01
      • 2011-11-30
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多