使用带有GoDaddy托管电子邮件的Nodemailer发送电子邮件

时间:2017-06-30 19:17:52

标签: shared-hosting nodemailer

我正在尝试使用nodemailer发送电子邮件,并通过GoDaddy配置自定义电子邮件地址。以下是"自定义配置的屏幕截图" c面板中的页面: enter image description here

和我的代码:

const nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: 'Godaddy',
  secureConnection: false,
  auth: {
    user: 'info@mywebsite.com',
    pass: 'mypassword'
  }
});

var mailOptions = {
  from: 'info@mywebsite.com',
  to: 'otheremail@gmail.com',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!',
  html: '<h1>Welcome</h1><p>That was easy!</p>'
};

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

和我的错误日志:

{ Error: connect EHOSTUNREACH 173.201.192.101:25
    at Object.exports._errnoException (util.js:1012:11)
    at exports._exceptionWithHostPort (util.js:1035:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
    code: 'ECONNECTION',
    errno: 'EHOSTUNREACH',
    syscall: 'connect',
    address: '173.201.192.101',
    port: 25,
    command: 'CONN' }

我尝试更改端口号,使用我的网站地址作为主机,使其成为非ssl的安全,以及我能想到的其他所有内容。我已成功使用其中一个网络邮件客户端从godaddy电子邮件发送了一封电子邮件。有没有其他人遇到这个或有关于尝试的事情的建议?

5 个答案:

答案 0 :(得分:3)

你应该在运输车上做一些改变:

Item1

答案 1 :(得分:2)

我意识到这是一篇过时的文章,但由于GoDaddy SMTP服务器已更改,因此我想补充一下,以防万一其他人遇到此问题并遇到与我相同的问题。 @tirmey的回答对我不起作用,但确实如此。

let nodemailer = require('nodemailer');

let mailerConfig = {    
    host: "smtp.office365.com",  
    secureConnection: true,
    port: 587,
    auth: {
        user: "username@email.com",
        pass: "password"
    }
};
let transporter = nodemailer.createTransport(mailerConfig);

let mailOptions = {
    from: mailerConfig.auth.user,
    to: 'SomePerson@email.com',
    subject: 'Some Subject',
    html: `<body>` +
        `<p>Hey Dude</p>` +
        `</body>`
};

transporter.sendMail(mailOptions, function (error) {
    if (error) {
        console.log('error:', error);
    } else {
        console.log('good');
    }
});

答案 2 :(得分:2)

我正在尝试使用GoDaddy SMTP设置使用来自Google Cloud Function的nodemailer发送电子邮件。我的GoDaddy主机上没有启用Office365。今天(2019年11月12日),以上选项均不适用于我。需要启用TLS。

我必须使用以下配置:

const mailTransport = nodemailer.createTransport({    
    host: "smtpout.secureserver.net",  
    secure: true,
    secureConnection: false, // TLS requires secureConnection to be false
    tls: {
        ciphers:'SSLv3'
    },
    requireTLS:true,
    port: 465,
    debug: true,
    auth: {
        user: "put your godaddy hosted email here",
        pass: "put your email password here" 
    }
});

然后,我可以发送如下测试电子邮件:

const mailOptions = {
            from: `put your godaddy hosted email here`,
            to: `bharat.biswal@gmail.com`,
            subject: `This is a Test Subject`,
            text: `Hi Bharat    

            Happy Halloween!

            If you need any help, please contact us.
            Thank You. And Welcome!

            Support Team
            `,

        };

mailTransport.sendMail(mailOptions).then(() => {
            console.log('Email sent successfully');
        }).catch((err) => {
            console.log('Failed to send email');
            console.error(err);
        });

答案 3 :(得分:1)

以上提出的解决方案似乎不再有效,它们都不适合我。以下解决方案对我有效:

def Foo(): def f(): def g():

答案 4 :(得分:-1)

此错误最常见的问题是防病毒。因此,如果您在本地测试它,请将其禁用10分钟。