Use smtp client to send email without providing password

有些话、适合烂在心里 提交于 2020-07-23 12:59:05

问题


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 👥" <foo@blurdybloop.com>', // sender address
    to: 'person@gmail.com', // 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 person@gmail.com < testemail.txt

How can I do this using nodemailer?


回答1:


Try port 587.

Here are my gmail settings.

smtpServerName="smtp.gmail.com" 
portNumber="587" 
authenticationMode="SSL" 
smtpUserName="somebody@gmail.com" 
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: 'my.username@gmail.com',
    pass: 'my.password'
}

Make sure you read this:

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



来源:https://stackoverflow.com/questions/36796891/use-smtp-client-to-send-email-without-providing-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!