Meteor deploy - MAIL_URL not being set

倖福魔咒の 提交于 2019-12-22 11:00:56

问题


I recently started deploying a meteor app off of my local machine and it seems that the MAIL_URL property is not being set when deploying to a *.meteor.com domain. No matter what I have tried the email is sent via the default MailGun

What I have tried so far.

  1. Verified that process.MAIL_URL is set and works locally - ensures that I am setting MAIL_URL correctly
  2. Verified that process.MAIL_URL is set on *.meteor.com domain by checking meteor logs - ensures that the process.env settings are being set on *.meteor.com
  3. Tried multiple *.meteor.com domains - ensures it was not a subdomain specific issue
  4. Tried multiple smtp providers: gmail and Mandrill - ensures that it was not an issue with the smtp provider
  5. Tried creating a simple app with a simple test email button - ensures problem was not related to my app code

Nothing works. With the simple app, my code is the following:

if (Meteor.isClient) {
  Template.hello.greeting = function () {
    return "Welcome to testmail.";
  };

  Template.hello.events({
    'click input' : function () {
      console.log("calling send mail");
      Meteor.call('sendEmail',
            'xxx@gmail.com',
            'xxx@domain.com',
            'Hello from Meteor!',
            'This is a test of Email.send.');           
    }
  });
}

if (Meteor.isServer) {
// In your server code: define a method that the client can call
Meteor.methods({
  sendEmail: function (to, from, subject, text) {
    check([to, from, subject, text], [String]);

    // Let other method calls from the same client start running,
    // without waiting for the email sending to complete.
    this.unblock();

    Email.send({
      to: to,
      from: from,
      subject: subject,
      text: text
    });
  }
});
  Meteor.startup(function () {
    // code to run on server at startup
    process.env.MAIL_URL = 'smtp://blahblah:token@smtp.mandrillapp.com:587/';      
    console.log(process.env);
  });
}

I am out of ideas at this point. Has anybody else experience this before and what was the resolution? Thanks.


回答1:


By default meteor deploy can only use mailgun since you can't alter the environmental variables on meteor deploy hosting. Additionally meteor deploy hosting uses a galaxy configuration which takes precedence over environmental variables.

If you take a look at [this file] meteor deploy hosting uses some kind of App configuration that configures it over the environmental variable (see https://github.com/meteor/meteor/blob/devel/packages/email/email.js#L42). This is part of the galaxy configuration engine.

You have to modify the Email package to use a custom smtp server. To do this :

  1. get the files from https://github.com/meteor/meteor/tree/devel/packages/email and place them in a directory in your project /packages/email.

  2. add this package to your meteor project with meteor add email. It should override the default meteor-core package. If it says already using, thats okay.

  3. Modify /packages/email/email.js around line 36 to be:

    var smtpPool = makePool("<YOUR CUSTOM MAIL_URL>");

Then you should be good to go. Meteor should use this smtp host instead, even on meteor.com hosting.



来源:https://stackoverflow.com/questions/20337309/meteor-deploy-mail-url-not-being-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!