使用nodemailer发送电子邮件 [英] Sending emails with nodemailer

查看:88
本文介绍了使用nodemailer发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用nodemailer从我的应用程序发送电子邮件。

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

我的设置如下所示:

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodemailer.createTransport(smtpTransport ({
  host: 'smtp.companyname.dk',
  secureConnection: true,
  port: 587,
  auth: {
        user: 'support@companyname.dk',
        pass: '****'
  }
}));

var mailOptions = {
    from: 'Olaf <ob@companyname.dk>',
    to: 'john@test.dk',
    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.companyname.dk. is not in the cert's altnames: DNS:*.mailcloud.dk, DNS:mailcloud.dk"]
  reason: 'Host: smtp.companyname.dk. is not in the cert\'s altnames: DNS:*.mailcloud.dk, DNS:mailcloud.dk',
  host: 'smtp.companyname.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).

推荐答案

尝试添加:

    tls: {
        rejectUnauthorized: false
    },

到您的nodemailer选项对象。

To your nodemailer options object.

这篇关于使用nodemailer发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆