Sending email via Node.js using nodemailer is not working

后端 未结 9 1785
悲&欢浪女
悲&欢浪女 2020-11-29 20:15

I\'ve set up a basic NodeJS server (using the nodemailer module) locally (http://localhost:8080) just so that I can test whether the server can actually send ou

相关标签:
9条回答
  • 2020-11-29 21:10

    While the above answers do work, I'd like to point out that you can decrease security from Gmail by the following TWO steps.

    STEP #1

    Google Account: sign-in attempt blocked If this was you You can switch to an app made by Google such as Gmail to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecureapps so that your account is no longer protected by modern security standards.

    STEP #2

    In addition to enabling Allow less secure apps, you might also need to navigate to https://accounts.google.com/DisplayUnlockCaptcha and click continue.

    0 讨论(0)
  • 2020-11-29 21:14

    Adding to xShirase answer just providing screenshots where to enable. Also confirm in security that previous attempt was from you.

    Xshirase deserves all upvotes.Iam just showing screenshot.

    0 讨论(0)
  • 2020-11-29 21:18

    The answer is in the message from google.

    • Go to : https://www.google.com/settings/security/lesssecureapps

    • set the Access for less secure apps setting to Enable

    For the second part of the problem, and in response to

    I'm actually simply following the steps from the nodemailer github page so there are no errors in my code

    I will refer you to the nodemailer github page, and this piece of code :

    var transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
        user: 'gmail.user@gmail.com',
        pass: 'userpass'
    }
    });
    

    It differs slightly from your code, in the fact that you have : nodemailer.createTransport("SMTP". Remove the SMTP parameter and it works (just tested). Also, why encapsulating it in a http server? the following works :

    var nodemailer = require('nodemailer');
    var transporter = nodemailer.createTransport({
        service: 'Gmail',
        auth: {
            user: 'xxx',
            pass: 'xxx'
        }
    });
    
    console.log('created');
    transporter.sendMail({
    from: 'xxx@gmail.com',
      to: 'xxx@gmail.com',
      subject: 'hello world!',
      text: 'hello world!'
    });
    
    0 讨论(0)
提交回复
热议问题