1

I'm using nodemailer to try to send an email to myself via commandline:

var nodemailer = require('nodemailer');

// config
var smtpConfig = {
    host: 'smtp.myhost.com',
    port: 465,
    secure: false, // dont use SSL
    tls: {rejectUnauthorized: false} 
};

// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport(smtpConfig);

// setup e-mail data with unicode symbols
var mailOptions = {
    from: '"Fred Foo 👥" <[email protected]>', // sender address
    to: '[email protected]', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world 🐴', // plaintext body
    html: '<b>Hello world 🐴</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
    if(error){
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);
});

When I try to run this code I get the following error:

Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8  https://support.google.com/mail/answer/14257

The link takes you to a page that tells you to register your app inside Google Console. But this is not what I'm trying to do.

There are loads of email clients that can send an email to a gmail inbox without having to sign into that email account. This is what I'm trying to do. I'm trying to turn my terminal into an smtp client that can send a mail message to any inbox. This shouldn't require extensive authentication. How do I do this?

NOTE

Just to provide some perspective, I'm trying to replicate in node whats possible with the unix sendmail command:

sendmail [email protected] < testemail.txt

How can I do this using nodemailer?

9
  • 1
    sending to gmail is entirely different than using gmail to send an email.
    – Marc B
    Apr 22, 2016 at 14:50
  • I know... I am trying to send to gmail.
    – dopatraman
    Apr 22, 2016 at 14:51
  • @Mark B. I think you summed up the issue in one brief thought. I didn't "see it" early enough me thinks. Apr 22, 2016 at 15:18
  • @MarcB Although this may be true, to someone who doesn't understand it sounds like a riddle. What is the difference?
    – dopatraman
    Apr 22, 2016 at 15:21
  • You're asking why [insert SMTP server here] isn't an Open Mail Relay, and why Open Mail Relays no longer are common. That link should splain you.
    – James
    Apr 22, 2016 at 19:01

1 Answer 1

-1

Try port 587.

Here are my gmail settings.

smtpServerName="smtp.gmail.com" 
portNumber="587" 
authenticationMode="SSL" 
smtpUserName="[email protected]" 
smtpUserPassword="xxxxxxxxxx"

I would experiment with ssl: false and ssl: true

nodemailer.SMTP = {
    host: 'smtp.gmail.com',
    port: 587,
    ssl: false,
    use_authentication: true,
    user: '[email protected]',
    pass: 'my.password'
}

Make sure you read this:

https://support.google.com/accounts/answer/6010255

It looks like there are two ways with gmail.

Port 587 is (non ssl) but with TLS.

Port 465 is SSL (but not TLS).

Go figure.

    //singleServer = new SmtpServerSettings("smtp.gmail.com",
    //      "[email protected]", "587", AuthenticationType.Basic,
    //    "[email protected]", "mypassword", "");

    //singleServer = new SmtpServerSettings("smtp.gmail.com",
    //      "[email protected]", "465", AuthenticationType.SSL,
    //      "[email protected]", "mypassword", "");
10
  • So here's the thrust of my question: I dont see why i need to provide a user name and password. I'm not signing into a service. I'm basically trying to wrap the sendmail command with a from and to address. Also, I get the same error even after switching to port 587.
    – dopatraman
    Apr 22, 2016 at 14:52
  • (most times, especially with a "cloud" smtp server) :: You need to provide credentials to the smtp service. This is how they know you are "legit". If you didn't supply credentials, anybody/everybody would sent emails via the gmail smtp servers.....aka, spam-city. I'm not sure why you would think otherwise. Apr 22, 2016 at 14:54
  • How can they authenticate a service that does not belong to google? What if I am using a third party unidentified smtp service? How would they authenticate?
    – dopatraman
    Apr 22, 2016 at 14:55
  • "Trying to send to gmail". What is your smtp server to plan on using? That's your fundamental question. Each smtp server has its own setup information. Apr 22, 2016 at 14:55
  • I am trying to write one from scratch. But for the time being I'm using a simple client to send a mail message. sendmail is able to do this without authentication. Why cant I replicate that in node?
    – dopatraman
    Apr 22, 2016 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.