Many solutions online regarding configuring Nodemailer to use your Gmail requires you to enable less secure app access. If that sounds too scary fo...
For further actions, you may consider blocking this person and/or reporting abuse
I am getting this error . UnhandledPromiseRejectionWarning: Failed to create access token :(
(Use
node --trace-warnings ...
to show where the warning was created)(node:7900) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict
(see nodejs.org/api/cli.html#cli_unhand...). (rejection id: 1)(node:7900) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise
As sendEMail is a async function try add try-catch block inside sendEmail function.
I'm getting the same, did you find a solution?
As sendEMail is a async function try adding try-catch block inside sendEmail function.
After adding try catch block getting "Error: No refresh token or refresh handler callback is set." this error. Any way to make it right?
Hi
I'm consistently getting this error:
"Failed to create access token: Error: invalid_grant" after having an app work fine for a week or so. After this period this error pops up.
I go to OAuth playground to regenerate the refreshToken. App works fine only to fail sometime later.
I pretty much followed (heck copied!! :-)) the code offered in this article.
Any ideas? Much appreciation in advance!
Add the email you are using to send email here in OAuth consent screen page as a test user
Hi. It's there already. But Thx for replying!!!
I will write a blog on it. once writing is completed, I will leave a link here
Thank you for your efforts! They are much appreciated.
Tony
I actually dont understand what happens next, in production. I guess oauthplayground does not stay there and we need to implement our authorization endpoint (redirect_uri) which is not much covered in the article. I think we should not use oauthplayground refresh token in production?
please am having a problem with sending dynamic email using nodemailer express handlebars here is my code
import nodemailer from "nodemailer"
import {
google
} from "googleapis"
import fs from "fs"
import path from "path"
import url from "url"
import expressHandlerbars from "nodemailer-express-handlebars"
const filename = url.fileURLToPath(import.meta.url)
const __dirname = path.dirname(filename)
const OAuth2 = google.auth.OAuth2
const createTransporter = async () => {
const OAuth2Client = new OAuth2(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
"developer.google.com/oauthplayground"
)
OAuth2Client.setCredentials({
refresh_token: process.env.REFRESH_TOKEN
})
const accessToken = await new Promise((resolve, reject)=> {
OAuth2Client.getAccessToken((error, token => {
if (error) {
console.log(error)
reject("Failed to get accessToken")
}
resolve(token)
}))
})
return await nodemailer.createTransport({
service: "gmail",
auth: {
type: "OAuth2",
accessToken,
user: process.env.EMAIL,
refreshToken: process.env.REFRESH_TOKEN,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
}, tsl: {
rejectUnauthorized: false
}
})
}
const sendMail = async (email, subject, payload, template)=> {
const options = {
from: process.env.EMAIL,
to: email,
subject:subject,
template: template,
context: payload,
}
try {
const transporter = await createTransporter()
} catch(error) {
console.log(
${error}
)}
}
export default sendMail
so I am receiving a reference error how can I fix it and do it in the right way
I am getting the following error:
Error: Invalid login: 535-5.7.8 Username and Password not accepted.
It works correct when I run your program in a standalone mode, but when I am your logic to my project, I get the above error.
Were you able to fix the issue?
Thank you so much, Chandra!
I was able to follow your directions for my Next.js application and got it to work!
This OAUTH stuff is definitely not intuitive, though.
For anyone struggling with implementing this, here is the GitHub link for my little project: github.com/jason-warner/hustlin-la...
And a few tips:
This is much easier to do now! stackoverflow.com/a/45479968/12104850
Hey,
Thanks for this post.
Refresh token expires in one week for me is it normal ?
Thanks
When I'm clicking to authorize API's and selecting my google account I'm getting this error: "appname has not completed the Google verification process. The app is currently being tested, and can only be accessed by developer-approved testers. If you think you should have access, contact the developer.
If you are a developer of appname, see error details.
Error 403: access_denied.
What's the point of using Nodemailer when you can send emails using just the Gmail API?
Its easier to implement i guess
Hi. I hope you're doing well. I used your method and everything works correctly, but only locally. In production (on Vercel for example), emails never go out. I do not understand. Can you help me please?
Good article but 'ridiculously easy though'? :/
Can anyone mention some simpler alternatives?
issue!
with authenticated email address even though I have provided with other email address with gmail domain.google always override from:
could you please help me out?
Too difficult, just to send an email
it is showing sendMail is not defined
Thanks for the post bro, it helped me a lot
This is an awesome blog. Learn a lots <3
So if I want to use nodemailer for production deployment, the googleapis package will allow for the token to never expire?
Great tutorial! Thanks for sharing
Worked at first try
How would you implement this via a NextJS application and use a contact form submission to send the details to a Gmail email?