I’m trying to use nodemailer in my contact form to receive feedback and send them directly to an email. This is the form below.
<form method="post" action="/contact">
<label for="name">Name:</label>
<input type="text" name="name" placeholder="Enter Your Name" required><br>
<label for="email">Email:</label>
<input type="email" name="email" placeholder="Enter Your Email" required><br>
<label for="feedback">Feedback:</label>
<textarea name="feedback" placeholder="Enter Feedback Here"></textarea><br>
<input type="submit" name="sumbit" value="Submit">
</form>
This is what the request in the server side looks like
app.post('/contact',(req,res)=>{
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'user@gmail.com',
password: 'password'
}
});
var mailOptions = {
from: req.body.name + '<' + req.body.email + '>',
to: 'bantspl@gmail.com',
subject: 'Plbants Feedback',
text: req.body.feedback
};
transporter.sendMail(mailOptions,(err,res)=>{
if(err){
console.log(err);
}
else {
}
});
I’m getting the error Missing credentials for "PLAIN"
. Any help is appreciated, thank you very much.
asked Feb 18, 2018 at 16:42
You have
auth: {
user: 'user@gmail.com',
password: 'password'
}
But you should write this
auth: {
user: 'user@gmail.com',
pass: 'password'
}
Just rename password to pass.
answered Oct 16, 2019 at 17:50
2
I was able to solve this problem by using number 3, Set up 3LO authentication, example from the nodemailer documentation (link: https://nodemailer.com/smtp/oauth2/). My code looks like this:
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: 'user@example.com',
clientId: '000000000000-xxx0.apps.googleusercontent.com',
clientSecret: 'XxxxxXXxX0xxxxxxxx0XXxX0',
refreshToken: '1/XXxXxsss-xxxXXXXXxXxx0XXXxxXXx0x00xxx',
accessToken: 'ya29.Xx_XX0xxxxx-xX0X0XxXXxXxXXXxX0x'
}
});
If you looked at the example in the link that I stated above, you can see there that there is a ‘expires’ property but in my code i didn’t include it and it still works fine.
To get the clientId, clientSecret, refreshToken, and accessToken, I just watched this video https://www.youtube.com/watch?v=JJ44WA_eV8E .
I don’t know if this is still helpful to you tho.
answered Jul 10, 2018 at 0:54
1
Gmail / Google app email service requires OAuth2 for authentication. PLAIN text password will require disabling security features manually on the google account.
To use OAuth2 in Nodemailer, refer: https://nodemailer.com/smtp/oauth2/
Sample code:
var email_smtp = nodemailer.createTransport({
host: "smtp.gmail.com",
auth: {
type: "OAuth2",
user: "youremail@gmail.com",
clientId: "CLIENT_ID_HERE",
clientSecret: "CLIENT_SECRET_HERE",
refreshToken: "REFRESH_TOKEN_HERE"
}
});
And if you still want to use just plain text password, disable secure login on your google account and use as follows:
var email_smtp = nodemailer.createTransport({
host: "smtp.gmail.com",
auth: {
type: "login", // default
user: "youremail@gmail.com",
pass: "PASSWORD_HERE"
}
});
answered Feb 22, 2018 at 10:21
1
We don’t need to lower our Google Account Security for this. This works for me on localhost and live server. Versions: node 12.18.4
, nodemailer ^6.4.11
.
STEP 1:
Follow setting up your Google Api Access in this video AND IGNORE his code (it didn’t work for me): https://www.youtube.com/watch?v=JJ44WA_eV8E
STEP 2:
Try this code in your main app file after you install nodemailer and dotenv via npm i nodemailer dotenv
:
require('dotenv').config(); //import and config dotenv to use .env file for secrets
const nodemailer = require('nodemailer');
function sendMessage() {
try {
// mail options
const mailOptions = {
from: "MySite@mysite.com",
to: "my_gmail@gmail.com",
subject: "Hey there!",
text: "Whoa! It freakin works now."
};
// here we actually send it
transporter.sendMail(mailOptions, function(err, info) {
if (err) {
console.log("Error sending message: " + err);
} else {
// no errors, it worked
console.log("Message sent succesfully.");
}
});
} catch (error) {
console.log("Other error sending message: " + error);
}
}
// thats the key part, without all these it didn't work for me
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
service: 'gmail',
auth: {
type: "OAUTH2",
user: process.env.GMAIL_USERNAME, //set these in your .env file
clientId: process.env.OAUTH_CLIENT_ID,
clientSecret: process.env.OAUTH_CLIENT_SECRET,
refreshToken: process.env.OAUTH_REFRESH_TOKEN,
accessToken: process.env.OAUTH_ACCESS_TOKEN,
expires: 3599
}
});
// invoke sending function
sendMessage();
Your .env
file for the above code should look similar to this:
GMAIL_USERNAME=your_mail@gmail.com
GMAIL_PASSWORD=lakjrfnk;wrh2poir2039r
OAUTH_CLIENT_ID=vfo9u2o435uk2jjfvlfdkpg284u3.apps.googleusercontent.com
OAUTH_CLIENT_SECRET=og029503irgier0oifwori
OAUTH_REFRESH_TOKEN=2093402i3jflj;geijgp039485puihsg[-9a[3;wjenjk,ucv[3485p0o485uyr;ifasjsdo283wefwf345w]fw2984329oshfsh
OAUTH_ACCESS_TOKEN=owiejfw84u92873598yiuhvsldiis9er0235983isudhfdosudv3k798qlk3j4094too283982fs
answered Sep 28, 2020 at 10:22
1
For me the issue was that I wasn’t accessing the .env file variables properly (I assume you’re storing your email and password in a .env file too). I had to add this to the top of the file:
const dotenv = require('dotenv');
dotenv.config();
Once I did that I could fill out the «auth» portion of the credentials like this:
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASSWORD
}
Of course you need to replace EMAIL_USERNAME and EMAIL_PASSWORD with whatever you called those variables in your .env file.
answered Mar 23, 2021 at 22:54
AlexAlex
2,0323 gold badges25 silver badges45 bronze badges
For me it happened because I forgot to npm install dotenv and require(‘dotenv’).config();
answered Nov 4, 2020 at 20:42
I came across this issue when deploying my app to Heroku. I was sending emails fine locally, but when I pushed a new build to Heroku, I got the dreaded Missing credentials for "PLAIN"
error. My issue was that I hadn’t separately setup the .env variables in Heroku.
If you go to your dashboard in Heroku, you can manually set up the config variables and that solved the problem for me.
Or you can do via Heroku CLI — good tutorial here
answered Jun 16, 2021 at 10:09
Steve BSteve B
5104 silver badges11 bronze badges
1
I was running ts-node in a folder that didn’t have the .env file.
So my process.env.GMAIL_EMAIL
and process.env.GMAIL_PASS
weren’t defined.
When I ran it in the directory with the .env
, it worked
answered Dec 14, 2020 at 14:28
If you are going to use the basic authentication (your current configuration) you will need to activate less secure app access from the following link to your google account which was stated in node mailer site here.
Also for more secure way, I recommend to take a look on the two following links:
- Sending Emails Securely Using Node.js, Nodemailer, SMTP, Gmail, and OAuth2 This will explain both simple/Basic and the secure methods to you.
- Using OAuth2 in nodemailer official docs, which contain a more simplified version of the secure method (but you will need to follow the steps mentioned in the first link till you get the client_ID,client_Secret, Refresh_Token, and Access Token before proceeding with it).
Note: if you are going to use the secure way from the first link steps you should modify the auth attributes to add the type option like the following:
auth: {
type: ‘OAuth2’,
user: process.env.EMAIL,
accessToken,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
refresh_token: process.env.REFRESH_TOKEN
}
because without stating explicitly that you are using OAuth2 method it will print the same error to you (based on my recent trials using the written code in that link)
answered Mar 11, 2021 at 2:06
For me it was because I forgot to add my Gmail password to my .env file.
answered Jun 23, 2020 at 13:42
Google disabled less secure apps, to resolve the issue one need to setup «Login with app password» and to allow the app password «setup two factor authentication»
when 2-Step-Verification is on and one get a «password incorrect» error, sign in to your account and go to security, try to use an App Password.
transport: {
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'contact@gmail.com',
pass: 'app password',
},
},
answered Jul 18, 2022 at 13:32
NehaNeha
1505 bronze badges
This happened to me when I tried to send mail to MailHog, a development local mailserver which runs on port 1025, and uses no username/password by default.
My code was providing empty username/password, but in fact you should provide no credentials at all.
This does not work (results in ‘Missing credentials for «PLAIN»‘):
const transport = require('nodemailer').createTransport({
host: mailhog,
port: 1025,
secure: false,
auth: {
user: '',
pass: '',
},
});
But this works:
const transport = require('nodemailer').createTransport({
host: mailhog,
port: 1025,
secure: false,
});
answered Jul 26, 2022 at 3:24
alberto56alberto56
2,9182 gold badges27 silver badges44 bronze badges
If you are expecting this (ERROR Send Error: Missing credentials for «PLAIN») error, it’s probably because you are testing on localhost.
For example, if you are using Heroku, simply try to deploy your project and test it in production.
Regards.
answered Nov 2, 2022 at 7:01
I encountered the same problem, and that was caused by Google automatically blocked your logging-in form untruthful third-party software. Then you can just turn this feature off in your Google account management.
Regards,
answered Apr 13, 2021 at 7:36
Complete the following form to have your issue reviewed
I am receiving following error
(node:14889) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Missing credentials for "PLAIN"
1. Is this a bug in Nodemailer?
- Yes
- No
Note. Non bug issues are closed by default. Head to Stack Overflow for support questions: https://stackoverflow.com/search?q=nodemailer
2. Is this related to Gmail / Hotmail / Yahoo?
- Yes
- No
Note. If you can not log in to Gmail then Gmail is blocking you. These issues are closed by default.
3. Is your issue related to SSL/TLS errors?
- Yes
- No
Note. Most probably you are trying to connect to a server with a self-signed/expired cert or the server supports only ancient ciphers or you are using an antivirus that intercepts your internet connection. Such issues are closed by default.
4. Is your issue related to connection timeouts
- Yes
- No
Note. Most probably you are firewalled out from the server. Such issues are closed by default.
5. Do you get SyntaxError when using Nodemailer?
- Yes
- No
Note. You are using too old version of Node.js, please upgrade. Such issues are closed by default.
6. Nodemailer version you are having problems with (eg. v1.3.7)
v4.5.0
…
7. Node.js version you are using (run node -v
to see it, eg v5.5.0)
v6.6.0
…
8. Your operating system (eg. Windows 10, Ubuntu 14.04 etc.)
Ubuntu 16.04
…
9. Nodemailer configuration settings (if applicable)
const nodemailer = require('nodemailer');
const xoauth2 = require('xoauth2');
const config = require('../../config');
/**
* @param {{ text: String, from: String, to: String, subject: String, html: String }} options
* @returns {Promise<any>}
*/
module.exports = function sendMail(options) {
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
xoauth2: xoauth2.createXOAuth2Generator({
user: config.googleAuth.email,
clientId: config.googleAuth.clientID,
clientSecret: config.googleAuth.clientSecret,
refreshToken: config.googleAuth.refreshToken
})
}
});
return new Promise((resolve, reject) => {
transporter.sendMail(options, error => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
};
…
10. If possible, include a minimal test case that can be used to verify your issue (link to a gist would be great!)
…
Thanks!
What’s Causing This Error?
This error occurs on Node.js applications deployed on Heroku without proper configuration of environment variables. Additionally, you may also run into this error due to invalid configurations.
Solution — Here’s How To Resolve It
Resolving the error by updating configurations
Ensure that you have configured Nodemailer successfully. You may use the snippet shown below as a guide for configuring Nodemailer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
const transporter = nodemailer.createTransport({ service: 'gmail', // or your own SMTP providerauth: {user: 'your-gmail@gmail.com'}, // user -> important pass: 'your-password' // pass -> important (do not use password) }); const mailOptions = { from: 'SENDER-EMAIL', to: 'RECIPIENT-EMAIL', subject: 'SUBJECT', text: 'EMAIL BODY', }; transporter.sendMail(mailOptions,(err,res)=>{ if(err){ console.log(err); } else { console.log('The email was sent successfully'); } });
Additionally, if you are using Google SMTP servers, ensure that you have turned on Less Secure Sign In. For users that use Office 365, ensure that SMTP authentication is turned on for your Microsoft account.
Resolving the error in Heroku
You will need to configure your Nodemailer environment variables in the deployed Heroku application.
To do so, first, log in to your Heroku console. Afterward, click on the deployed application and click «Settings.» You will see the output shown below.
Figure 01 — Heroku application settings
Hereafter, click on «Reveal Config Vars.» It will display the output shown below.
Figure 02 — Viewing config variables in the Heroku console
Then, add the environment variables that you use with Nodemailer.
Figure 03 — Adding config variables to Heroku
Finally, re-rerun the application to see the emails getting sent successfully!
Resolving steps if none of the above works
If none of the actions work for you, ensure that you have provided the correct username/password, port, and protocol. Additionally, if you use dotenv
to load the environment file, ensure that you properly access the configurations.
1 2 3 4 5 6
// add this snippet to the top of your Node.js file to initialize the .env file that you have created to store the env variables. const dotenv = require('dotenv'); dotenv.config(); // access env console.log(process.env.NODE_MAILER_USERNAME);
Answer by Journee Dougherty
I was able to solve this problem by using number 3, Set up 3LO authentication, example from the nodemailer documentation (link: https://nodemailer.com/smtp/oauth2/). My code looks like this:,If you are going to use the basic authentication (your current configuration) you will need to activate less secure app access from the following link to your google account which was stated in node mailer site here.,Using OAuth2 in nodemailer official docs, which contain a more simplified version of the secure method (but you will need to follow the steps mentioned in the first link till you get the client_ID,client_Secret, Refresh_Token, and Access Token before proceeding with it).,
Is it possible for LEO satellites to detect a usable signal from regular mobile phones on the ground?
I was able to solve this problem by using number 3, Set up 3LO authentication, example from the nodemailer documentation (link: https://nodemailer.com/smtp/oauth2/). My code looks like this:
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: '[email protected]',
clientId: '000000000000-xxx0.apps.googleusercontent.com',
clientSecret: 'XxxxxXXxX0xxxxxxxx0XXxX0',
refreshToken: '1/XXxXxsss-xxxXXXXXxXxx0XXXxxXXx0x00xxx',
accessToken: 'ya29.Xx_XX0xxxxx-xX0X0XxXXxXxXXXxX0x'
}
});
Answer by Whitley Davidson
i am having this issue as with node mailer,for anyone having this issue,check this out https://community.nodemailer.com/using-gmail/,According to an example i don`t have to provide username and password
(node:14889) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Missing credentials for "PLAIN"
Answer by Jose Patton
I’m trying to use nodemailer in my contact form to receive feedback and send them directly to an email. This is the form below.,I’m getting the error Missing credentials for «PLAIN». Any help is appreciated, thank you very much.,To use OAuth2 in Nodemailer, refer: https://nodemailer.com/smtp/oauth2/,Gmail / Google app email service requires OAuth2 for authentication. PLAIN text password will require disabling security features manually on the google account.
I’m trying to use nodemailer in my contact form to receive feedback and send them directly to an email. This is the form below.
<form method="post" action="/contact">
<label for="name">Name:</label>
<input type="text" name="name" placeholder="Enter Your Name" required><br>
<label for="email">Email:</label>
<input type="email" name="email" placeholder="Enter Your Email" required><br>
<label for="feedback">Feedback:</label>
<textarea name="feedback" placeholder="Enter Feedback Here"></textarea><br>
<input type="submit" name="sumbit" value="Submit">
</form>
This is what the request in the server side looks like
app.post('/contact',(req,res)=>{
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
password: 'password'
}
});
var mailOptions = {
from: req.body.name + '<' + req.body.email + '>',
to: '[email protected]',
subject: 'Plbants Feedback',
text: req.body.feedback
};
transporter.sendMail(mailOptions,(err,res)=>{
if(err){
console.log(err);
}
else {
}
});
Answer by Everleigh O’Donnell
var email_smtp = nodemailer.createTransport({
host: "smtp.gmail.com",
auth: {
type: "login", // default
user: "[email protected]",
pass: "PASSWORD_HERE"
}
});
Answer by Sloane Leon
Custom authentication
,text is the readable part of server response (“Authentication successful”),NTLM handler to authenticate using NTLM,Authentication options can be found from the auth property and credentials from auth.credentials (eg. ctx.auth.credentials.pass for the password)
let transporter = nodemailer.createTransport({
host: 'smtp.example.com',
port: 465,
secure: true,
auth: {
type: 'custom',
method: 'MY-CUSTOM-METHOD', // forces Nodemailer to use your custom handler
user: 'username',
pass: 'verysecret'
},
customAuth: {
'MY-CUSTOM-METHOD': ctx => {
...
}
}
});
Answer by Sloane Bishop
Example 1: Error: Missing credentials for «PLAIN»
var email_smtp = nodemailer.createTransport({
host: "smtp.gmail.com",
auth: {
type: "login", // default
user: "[email protected]",
pass: "PASSWORD_HERE"
}
});
Example 2: Error: Missing credentials for «PLAIN»
var email_smtp = nodemailer.createTransport({
host: "smtp.gmail.com",
auth: {
type: "OAuth2",
user: "[email protected]",
clientId: "CLIENT_ID_HERE",
clientSecret: "CLIENT_SECRET_HERE",
refreshToken: "REFRESH_TOKEN_HERE"
}
});
Answer by Belle Estrada
When submitting the form, it gives an error Error: Missing credentials for «PLAIN»,Askto.pro is Information Technologies oriented Questions and Answers platform.,
Most Interesting
,You must login or register to add a new answer.
const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.post('/contacts', (req, res) => {
nodemailer.createTestAccount((err, account) => {
const htmlEmail = `
<h3>Contact details</h3>
<ul>
<li>Name: ${req.body.name}</li>
<li>Email: ${req.body.email}</li>
</ul>
<h3>Message</h3>
<p>${req.body.message}</p>
`;
let transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
port: 587,
secure: true,
requireTLS: true,
auth: {
user: process.env.REACT_APP_EMAIL,
pass: process.env.REACT_APP_PASS
}
})
transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
let mailOptions = {
from: '',
to: '[email protected]',
subject: 'New message',
text: req.body.message,
html: htmlEmail
}
transporter.sendMail(mailOptions, (err, info) => {
if(err) {
return console.log(err)
}
console.log('Message sent: %s', info.message)
// console.log('Message URL: %s', nodemailer.getTestMessageUrl(info))
})
})
})
const PORT = process.env.PORT || 3001;
if (process.env.NODE_ENV === 'production') {
// Serve any static files
app.use(express.static(path.join(__dirname, 'client/build')));
// Handle React routing, return all requests to React app
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
}
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
})
Answer by Orlando Foley
Find more questions by tags Node.jsExpress.js
const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.post('/contacts', (req, res) => {
nodemailer.createTestAccount((err, account) => {
const htmlEmail = `
the <h3>Contact details</h3>
the <ul>
the <li>Name: ${req.body.name}</li>
the <li>Email: ${req.body.email}</li>
</ul>
the <h3>Message</h3>
<p>${req.body.message}</p>
`;
let transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
port: 587,
secure: true,
requireTLS: true,
auth: {
user: process.env.REACT_APP_EMAIL,
pass: process.env.REACT_APP_PASS
}
})
transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
let mailOptions = {
from:"
to: '[email protected]',
subject: 'New message',
text: req.body.message
html: htmlEmail
}
transporter.sendMail(mailOptions, (err, info) => {
if(err) {
return console.log(err)
}
console.log('Message sent: %s', info.message)
// console.log('Message URL: %s' nodemailer.getTestMessageUrl(info))
})
})
})
const PORT = process.env.PORT || 3001;
if (process.env.NODE_ENV === 'production') {
// Serve any static files
app.use(express.static(path.join(__dirname, 'client/build')));
// Handle routing React, return all requests to the React app
app.get('*', function(req, res) {
Res. sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
}
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
})
In this post, we will see how to resolve Why am I getting Error: Missing credentials for “PLAIN” when setting up a 3LO authentication with nodemailer and googleapis?
Question:
I am using nodemailer and googleapis to send emails from my Next.js API route but I am getting the following error: Error: Missing credentials for “PLAIN”
I followed this tutorial to set it up: https://blog.devgenius.io/correct-way-in-setting-up-nodemailer-for-email-service-946f6bfd73e8
I additionally looked at the nodemailer documentation to get sure that everything is up to date.
Nodemailer documentation example for a 3LO authentication setup: https://nodemailer.com/smtp/oauth2/#example-3
Here is my code:
I also added the tls property to the transporter as suggested in some of the tutorials I found even though it did not fix the problem.
I also tried to skip the properties host, port and secure and replaced them with service. Again, that did not make a difference.
As suggested in the comments I followed the instructions and I changed my code accordingly to this:
But again the same error appeared:
Best Answer:
I had the same problem, Here is how I fixed it. Because I used Gmail I had to enable 2-factor authentication and then add Nodemailer
to App Passwords App Password Settings then use the generated password as the password for authentication
If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com
We don’t need to lower our Google Account Security for this. This works for me on localhost and live server. Versions: node 12.18.4
, nodemailer ^6.4.11
.
STEP 1:
Follow setting up your Google Api Access in this video AND IGNORE his code (it didn’t work for me): https://www.youtube.com/watch?v=JJ44WA_eV8E
STEP 2:
Try this code in your main app file after you install nodemailer and dotenv via npm i nodemailer dotenv
:
require('dotenv').config(); //import and config dotenv to use .env file for secrets
const nodemailer = require('nodemailer');
function sendMessage() {
try {
// mail options
const mailOptions = {
from: "[email protected]",
to: "[email protected]",
subject: "Hey there!",
text: "Whoa! It freakin works now."
};
// here we actually send it
transporter.sendMail(mailOptions, function(err, info) {
if (err) {
console.log("Error sending message: " + err);
} else {
// no errors, it worked
console.log("Message sent succesfully.");
}
});
} catch (error) {
console.log("Other error sending message: " + error);
}
}
// thats the key part, without all these it didn't work for me
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
service: 'gmail',
auth: {
type: "OAUTH2",
user: process.env.GMAIL_USERNAME, //set these in your .env file
clientId: process.env.OAUTH_CLIENT_ID,
clientSecret: process.env.OAUTH_CLIENT_SECRET,
refreshToken: process.env.OAUTH_REFRESH_TOKEN,
accessToken: process.env.OAUTH_ACCESS_TOKEN,
expires: 3599
}
});
// invoke sending function
sendMessage();
Your .env
file for the above code should look similar to this:
[email protected]
GMAIL_PASSWORD=lakjrfnk;wrh2poir2039r
OAUTH_CLIENT_ID=vfo9u2o435uk2jjfvlfdkpg284u3.apps.googleusercontent.com
OAUTH_CLIENT_SECRET=og029503irgier0oifwori
OAUTH_REFRESH_TOKEN=2093402i3jflj;geijgp039485puihsg[-9a[3;wjenjk,ucv[3485p0o485uyr;ifasjsdo283wefwf345w]fw2984329oshfsh
OAUTH_ACCESS_TOKEN=owiejfw84u92873598yiuhvsldiis9er0235983isudhfdosudv3k798qlk3j4094too283982fs
Add Answer
|
View In TPC Matrix
Technical Problem Cluster First Answered On
April 21, 2020
Popularity
10/10
Helpfulness
5/10
Contributions From The Grepper Developer Community
Contents
Code Examples
Related Problems
TPC Matrix View Full Screen
Error: Missing credentials for «PLAIN»
Comment
0
Popularity
10/10 Helpfulness
5/10
Language
whatever
Source: stackoverflow.com
Tags: credentials
whatever
Contributed on Apr 21 2020
Xerothermic Xenomorph
8 Answers Avg Quality 7/10
Error: Missing credentials for «PLAIN»
Comment
0
Popularity
10/10 Helpfulness
4/10
Language
javascript
Source: stackoverflow.com
Tags: credentials
javascript
Contributed on Apr 21 2020
Xerothermic Xenomorph
8 Answers Avg Quality 7/10
Grepper
Features
Reviews
Code Answers
Search Code Snippets
Plans & Pricing
FAQ
Welcome
Browsers Supported
Grepper Teams
Documentation
Adding a Code Snippet
Viewing & Copying Snippets
Social
Twitter
LinkedIn
Legal
Privacy Policy
Terms
Contact
support@codegrepper.com
Привет, я пытаюсь настроить nodemailer с помощью Gmail, и пока что слежу за этим видео:
Вот мой код:
`
const nodemailer = require («nodemailer»);
const xoauth2 = требуется (‘xoauth2’);
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: "gmail",
auth: {
xoauth2: xoauth2.createXOAuth2Generator({
user: "[email protected]",
clientId: 'xxxxxxxxxxxxxxxxx',
clientSecret: 'xxxxxxxxxxxxxxxxx',
refreshToken: 'xxxxxxxxxxxxxxxxx'
})
}
});
// send mail with defined transport object
let mailOptions = {
from: '"Fred Foo 👻" <[email protected]>', // sender address
to: "[email protected]", // receiver address
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>" // html body
};
transporter.sendMail(mailOptions, (error, res) => {
if (error) {
console.log(error);
}else {
console.log("email is sent");
}
})
`
Я получаю эту ошибку:
{ Error: Missing credentials for "PLAIN"
at SMTPConnection._formatError (/home/xxxxxx/projects/my-projects/test/node_modules/nodemailer/lib/smtp-connection/index.js:781:19)
at SMTPConnection.login (/home/xxxxxx/projects/my-projects/test/node_modules/nodemailer/lib/smtp-connection/index.js:452:38)
at connection.connect (/home/xxxxx/projects/my-projects/test/node_modules/nodemailer/lib/smtp-transport/index.js:271:32)
at SMTPConnection.once (/home/xxxxx/projects/my-projects/test/node_modules/nodemailer/lib/smtp-connection/index.js:209:17)
at Object.onceWrapper (events.js:286:20)
at SMTPConnection.emit (events.js:198:13)
at SMTPConnection._actionEHLO (/home/xxxxxxx/projects/my-projects/test/node_modules/nodemailer/lib/smtp-connection/index.js:1309:14)
at SMTPConnection._processResponse (/home/xxxxxxxx/projects/my-projects/test/node_modules/nodemailer/lib/smtp-connection/index.js:940:20
)
at SMTPConnection._onData (/home/xxxxxxxxx/projects/my-projects/test/node_modules/nodemailer/lib/smtp-connection/index.js:746:14)
at TLSSocket.SMTPConnection._onSocketData (/home/xxxxxxxxx/projects/my-projects/test/node_modules/nodemailer/lib/smtp-connection/index.js
:189:46) code: 'EAUTH', command: 'API' }
Номера версий
ОС: Ubuntu 19.04
узел 10.16.0
nodemailer 6.3.0
Я не понимаю, какие учетные данные отсутствуют, поскольку я их предоставил. Я просмотрел почти все статьи по этой проблеме, и ни одна из них не помогла.
Также быстрый вопрос: можно ли использовать nodemailer только в приложении create-response-app без необходимости настраивать для него серверную часть?
заранее спасибо
Эта проблема была автоматически помечена как устаревшая, поскольку в последнее время не было активности. Он будет закрыт, если больше не будет активности. Спасибо за ваш вклад.
Вы когда-нибудь догадывались об этом? У меня крайний срок, и эта ошибка внезапно закралась в мой проект. Он работал нормально, и я думаю, что единственное, что я мог изменить между тем, когда он работал, и теперь — это аутентификация моей учетной записи Google. Любые идеи приветствуются!
Для меня это было из-за того, что я не добавлял свой пароль Gmail в файл .env.