计算引擎上的Nodemailer Sendgrid

时间:2015-11-11 09:43:57

标签: google-compute-engine sendgrid nodemailer

我尝试从我的计算引擎实例发送电子邮件但没有任何反应(没有错误消息)。当我从本地电脑发送邮件时,我收到了电子邮件。

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

var options = {};
var transporter = nodemailer.createTransport(smtpTransport({
    service: 'SendGrid',
    auth: {
        user: 'username',
        pass: 'password'
    }
}));
module.exports = {
    sendmailto : sendmailto
}

function sendmailto(emailfrom,emailto, message){

    var mailOptions = {
        from: emailfrom, // sender address
        to: emailto, // list of receivers
        subject: 'Monitoring', // Subject line
        text: message, // plaintext body
        html: '<b>Monitoring</b>' +
        '<p> '+message+'<p>' // html body
    };

  transporter.sendMail(mailOptions, function(error, info){
      if(error){
          return console.log(error);
      }else{
          console.log('Message send: ', + info.response);
      }

    });
};

1 个答案:

答案 0 :(得分:2)

我发现原因是我自己:)服务“Sendgrid使用标准端口25但是不能用于计算引擎所以我需要添加端口2525。

var transporter = nodemailer.createTransport(smtpTransport({
    service: 'SendGrid',
    port: '2525',
    auth: {
        user: 'username',
        pass: 'password'
    }
}));