简体   繁体   English

如何在Node.js脚本中从Gmail帐户发送电子邮件?

[英]How do I send email from my Gmail account in my Node.js script?

app.get('/email', function(req,res){
    var emailjs = require('emailjs');
    var email_server = emailjs.server.connect({
        host: 'smtp.gmail.com',
        ssl: true,
        tls: true,
        port: "465",
        user:'kateholloway@gmail.com',
        password:'mypassword',
    });

    var h={
        text: 'hey how you doing',
        from: 'Kate Holloway <kateholloway@gmail.com>',
        to: 'someonesemail@gmail.com',
        subject: 'where is your phone'
    };
    var message = emailjs.message.create(h);
    email_server.send(message, function(err,message){
        console.log(err);
        console.log(message);
        res.send('ok');
    });

});

Is this the right settings to do it? 这是正确的设置吗?

The error message I get is: 我收到的错误消息是:

{ [Error: connection has ended] code: 9, smtp: undefined }

Note: this code works with my own domain/server. 注意:此代码可用于我自己的域/服务器。 But it doesn't work with Gmail. 但不适用于Gmail。 Therefore, I think my settings for Gmail smtp are incorrect. 因此,我认为我的Gmail smtp设置不正确。

We have used this library with Gmail. 我们已将此库用于Gmail。 We have only set host, user, password and ssl options. 我们只设置了主机,用户,密码和ssl选项。 Its working as expected. 其工作按预期进行。 Try removing other options. 尝试删除其他选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM