【问题标题】:How can I send emails using my own mail server in Meteor?如何在 Meteor 中使用我自己的邮件服务器发送电子邮件?
【发布时间】:2014-05-30 21:10:36
【问题描述】:

我正在尝试启用email support for my Meteor application,因为我有自己的服务器,所以我也想使用自己的邮件服务器。所以我在我的Debian wheezy服务器上安装了postfix,并成功发送邮件到我的GMail地址,这意味着邮件服务器正常工作并发送邮件。

当我部署我的 Meteor 应用程序并尝试发送电子邮件时,说要重置密码,我的应用程序崩溃并出现以下错误:

Exception while invoking method 'forgotPassword' RecipientError: Can't send mail - all recipients were rejected
at Object.Future.wait (/home/loupax/phial/bundle/programs/server/node_modules/fibers/future.js:326:15)
at smtpSend (packages/email/email.js:94)
at Object.Email.send (packages/email/email.js:155)
...
...

我的MAIL_URL 环境变量格式为MAIL_URL=smtp://my_domain.tld

【问题讨论】:

  • @Flexo:虽然修复是单行的,但它是the Meteor documentation 中未提及的有用解决方案(并且不是像拼写错误那样的用户错误;而是缺少文档)。能否请您重新提出问题?

标签: email meteor smtp


【解决方案1】:

看起来我所要做的就是将MAIL_URL 环境变量从smtp://my_domain.tld 更改为smtp://localhost。之后一切正常

【讨论】:

  • 请注意,这适用于postfix,它是一个成熟的电子邮件服务器,但对于msmtp,这不起作用。尝试发送电子邮件时,我收到Exception while invoking method 'forgotPassword' Error: connect ECONNREFUSED at smtpSend (packages/email/email.js:94)
  • 就我而言,因为我使用的是 Docker。我还需要在我的 /etc/postfix/main.cfg 文件中信任 docker IP 范围:mynetworks = 127.0.0.0/8 172.17.0.0/16 [::ffff:127.0.0.0]/104 [::1]/128。 172.17.x.x 是 Docker 容器的范围。然后我可以使用 smtp://serverip 从 Docker 容器连接到运行 Postfix 的主机。
【解决方案2】:

您的服务器在亚马逊上吗?有时 SMTP 服务器会阻止某些托管服务提供商在整个 IP 范围内发送的任何内容,以阻止垃圾邮件。

您可能需要考虑使用不同的 SMTP 服务器,亚马逊的 SESMandrill(它有一个陨石包可以提供帮助)(我个人同时使用 SESMandrill)。

请注意,其中不仅包括亚马逊的 IP 块,还包括垃圾邮件发送者可以快速设置的任何托管服务提供商。您的 SMTP 服务器可能使用了来自某个地方的列表,上面包含所有这些 ips

【讨论】:

  • 服务器是 Debian Wheezy VPS,我有 root 访问权限。就像我说的,我可以从我的服务器发送电子邮件。例如,我从同一台机器上提供的 wordpress 可以正确发送电子邮件,所以问题肯定来自 node/meteor
  • @Loupax 您的 wordpress 是否使用相同的 SMTP 设置,或者您是否直接使用插件或其他东西进入 postfix?
  • 当我可以访问服务器时我会再次检查,但我当然也可以通过命令行发送电子邮件。 echo "This will go into the body of the mail." | mail -s "Hello world" me@gmail.com 例如有效,它会从我当前登录的帐户向我发送一封电子邮件
  • @Loupax 听起来它不是下一个导致问题的 SMTP 服务器,而是它的后缀位,尝试像从 Meteor 一样通过 SMTP 发送电子邮件,我猜后缀可能需要更多配置它认为您发送到的电子邮件是本地的,需要将其设置为向外发送任何内容以进行传递
  • 如果您使用Gmail,您还可以在您的Google Apps域的控制面板中设置MAIL_URL=smtp://smtp-relay.gmail.com:25/(无需任何密码)并将您服务器的IP列入白名单。请注意,Google 可能需要一段时间(1 小时?)才能将 IP 列入白名单,在此期间您将收到 Exception while invoking method 'forgotPassword' SenderError: Mail from command failed - 550 5.7.0 Mail relay denied - gsmtp
【解决方案3】:

对于忘记密码的电子邮件,请按照以下步骤操作

1) 在服务器文件夹中创建 smtp.js 文件并在其中粘贴以下代码

 Meteor.startup(function () {
   process.env.MAIL_URL = 
   'smtps://abcd@gmail.com:password@smtp.gmail.com:465';
 });

2) 将以下代码粘贴到忘记密码.js 文件中

   Template.forgot.events({

'click #forgot'(event,template) {
    event.preventDefault();

    let email = $("#email").val();

    // paste below code in server.main.js -> in Meteor.startup function.

    /* Accounts.urls.resetPassword = function(token) {
        return Meteor.absoluteUrl('reset-password/' + token);
    };*/

    Accounts.forgotPassword({email:email},function (error,result) {

        if(error)
        {
            alert(error);
        }
        else
        {
            console.log(result);
            alert("mail sent ..!! Check your mail box");
           FlowRouter.go('/login');
         }
      });
   }

 });

3 ) 在服务器文件夹中的 main.js 文件中粘贴以下代码 导入'../server/smtp';

Meteor.startup(() => {
  // code to run on server at startup
    Accounts.urls.resetPassword = function(token) {
        return Meteor.absoluteUrl('reset-password/' + token);
    };
});

检查你的邮件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-28
    • 2020-09-12
    • 1970-01-01
    • 2014-12-18
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    相关资源
    最近更新 更多