最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sending emails with nodemailer - Stack Overflow

programmeradmin7浏览0评论

I'm trying to send emails from my application using nodemailer.

My setup look like this:

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodemailer.createTransport(smtpTransport ({
  host: 'smtppanyname.dk',
  secureConnection: true,
  port: 587,
  auth: {
        user: '[email protected]',
        pass: '****'
  }
}));

var mailOptions = {
    from: 'Olaf <[email protected]>',
    to: '[email protected]',
    subject: 'This is a test ',
        text: 'Hello world ',
        html: '<b>Hello world </b>'
    };

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

After running this, it gives me the following error:

{ [Error: Hostname/IP doesn't match certificate's altnames: "Host: smtppanyname.dk. is not in the cert's altnames: DNS:*.mailcloud.dk, DNS:mailcloud.dk"]
  reason: 'Host: smtppanyname.dk. is not in the cert\'s altnames: DNS:*.mailcloud.dk, DNS:mailcloud.dk',
  host: 'smtppanyname.dk.',
  cert: 
   { subject: { OU: 'Domain Control Validated', CN: '*.mailcloud.dk' },
     issuer: { O: 'AlphaSSL', CN: 'AlphaSSL CA - G2' },
     subjectaltname: 'DNS:*.mailcloud.dk, DNS:mailcloud.dk',
     infoAccess: { 'CA Issuers - URI': [Object], 'OCSP - URI': [Object] },
     modulus: 'AFFDE405E26382FC1F9A126B51C763A21DCB90228DF9B9BFF466B00DA17BCBDA48E0315E0A6E4E8E0C65B3E5A9BF9A98448DF8006869B913C8D644B78B2176C240AA703DF7C5109F7FC9EDBAE0A69E35E00A81D753990A7DF531CC1F47A778A1CC18271298DBB71E341E846139951D9B119C237BDD9AA6F7D16A62FC5D4D6BEA0288DAC700E5C87E472B75365C522B0342185F16854659EE48637B6124269C4E18CC040344928D115350805EF66738922230349DEC97E2D68D0B4175EA6B63BC161B841C150B7009AAC0E8A06CD34D3912926D98CEBF83F6C187AD08A5045F9868512EFDD478FAA81FA0402F5C44B3FD70F82BA4F102352A01B02B77F0FA096D',
     exponent: '10001',
     valid_from: 'Oct  3 08:22:02 2014 GMT',
     valid_to: 'Dec 21 11:07:29 2017 GMT',
     fingerprint: '35:3A:87:5C:91:8C:B2:7C:4E:87:D1:E3:26:84:57:E5:A1:73:62:F3',
     ext_key_usage: [ '1.3.6.1.5.5.7.3.1', '1.3.6.1.5.5.7.3.2' ],
     serialNumber: '****',
     raw: <Buffer 30 82 04 a7 30 82 03 8f a0 03 02 01 02 02 12 11 21 75 e4 f8 11 73 a4 c5 05 36 5f fe 9b b3 0b 4f 86 30 0d 06 09 2a 86 48 86 f7 0d 01 01 05 05 00 30 2e ... > } }

I've been stuck with this for days now and looked everywhere, so I hope somebody can help me with this (or at least point at the right direction).

I'm trying to send emails from my application using nodemailer.

My setup look like this:

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodemailer.createTransport(smtpTransport ({
  host: 'smtp.panyname.dk',
  secureConnection: true,
  port: 587,
  auth: {
        user: '[email protected]',
        pass: '****'
  }
}));

var mailOptions = {
    from: 'Olaf <[email protected]>',
    to: '[email protected]',
    subject: 'This is a test ',
        text: 'Hello world ',
        html: '<b>Hello world </b>'
    };

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

After running this, it gives me the following error:

{ [Error: Hostname/IP doesn't match certificate's altnames: "Host: smtp.panyname.dk. is not in the cert's altnames: DNS:*.mailcloud.dk, DNS:mailcloud.dk"]
  reason: 'Host: smtp.panyname.dk. is not in the cert\'s altnames: DNS:*.mailcloud.dk, DNS:mailcloud.dk',
  host: 'smtp.panyname.dk.',
  cert: 
   { subject: { OU: 'Domain Control Validated', CN: '*.mailcloud.dk' },
     issuer: { O: 'AlphaSSL', CN: 'AlphaSSL CA - G2' },
     subjectaltname: 'DNS:*.mailcloud.dk, DNS:mailcloud.dk',
     infoAccess: { 'CA Issuers - URI': [Object], 'OCSP - URI': [Object] },
     modulus: 'AFFDE405E26382FC1F9A126B51C763A21DCB90228DF9B9BFF466B00DA17BCBDA48E0315E0A6E4E8E0C65B3E5A9BF9A98448DF8006869B913C8D644B78B2176C240AA703DF7C5109F7FC9EDBAE0A69E35E00A81D753990A7DF531CC1F47A778A1CC18271298DBB71E341E846139951D9B119C237BDD9AA6F7D16A62FC5D4D6BEA0288DAC700E5C87E472B75365C522B0342185F16854659EE48637B6124269C4E18CC040344928D115350805EF66738922230349DEC97E2D68D0B4175EA6B63BC161B841C150B7009AAC0E8A06CD34D3912926D98CEBF83F6C187AD08A5045F9868512EFDD478FAA81FA0402F5C44B3FD70F82BA4F102352A01B02B77F0FA096D',
     exponent: '10001',
     valid_from: 'Oct  3 08:22:02 2014 GMT',
     valid_to: 'Dec 21 11:07:29 2017 GMT',
     fingerprint: '35:3A:87:5C:91:8C:B2:7C:4E:87:D1:E3:26:84:57:E5:A1:73:62:F3',
     ext_key_usage: [ '1.3.6.1.5.5.7.3.1', '1.3.6.1.5.5.7.3.2' ],
     serialNumber: '****',
     raw: <Buffer 30 82 04 a7 30 82 03 8f a0 03 02 01 02 02 12 11 21 75 e4 f8 11 73 a4 c5 05 36 5f fe 9b b3 0b 4f 86 30 0d 06 09 2a 86 48 86 f7 0d 01 01 05 05 00 30 2e ... > } }

I've been stuck with this for days now and looked everywhere, so I hope somebody can help me with this (or at least point at the right direction).

Share Improve this question asked Mar 17, 2015 at 12:52 BackerBacker 1,1141 gold badge21 silver badges33 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 14

Try adding:

    tls: {
        rejectUnauthorized: false
    },

To your nodemailer options object.

After adding what @Richard Macarthy suggested, and looking up the new error I got back, I figured out that the from email in my mailOptions has to be the same as the email I'm using to send the emails from - which actually makes perfectly sense now.

In this case:

var mailOptions = {
    from: 'Olaf <[email protected]>',
    to: '[email protected]',
    ...
var transporter = nodemailer.createTransport({<br>
host: 'hostSTMP',
secure: false, //disable SSL    
requireTLS: true, //Force TLS
    tls: {
        rejectUnauthorized: false
    },
    port: port, //Port of STMP service
    auth: {
      user: '[email protected]',
      pass: 'password'
   }
});

rejectUnauthorized: If true, the server certificate is verified against the list of supplied CAs. An error event is emitted if verification fails; Default: true.

rejectUnauthorized: If false, you're saying "I don't care if I can't verify the server's identity."

发布评论

评论列表(0)

  1. 暂无评论