Having difficulty setting up nodemailer to connect with Gmail using oAuth2 authentication

I recently followed a tutorial on setting up nodemailer with gmail, which can be found here.

Here is how my transporter is configured:

const transportObj = {
  host: 'smtp.gmail.com',
  port: 465,
  secure: true,
  auth: {
    type: "OAuth2",
    user: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc918599919d9590bc9b919d9590d29f9391">[email protected]</a>",
    clientId: "xxxxxxxxxxx.apps.googleusercontent.com",
    clientSecret: "xxxxxxxx",
    refreshToken: "xxxxxxxxx",
    accessToken: "xxxxxxxxxxxxxxx"
  }
};

Unfortunately, when I try to create the transporter using this configuration:

let transporter = nodemailer.createTransport(transportObj);

I encounter the following error:

TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type'{ host: string; port: number; secure: boolean; auth: { type: string; user: string; serviceClient: string; privateKey: string; accessToken: string; }; }' is not assignable to parameter of type 'Transport | TransportOptions'.
      Type '{ host: string; port: number; secure: boolean; auth: { type: string; user: string; serviceClient: string; privateKey: string; accessToken: string; }; }' has no properties in common with type 'TransportOptions'.

467         transporter = nodemailer.createTransport(transportObj);

Even though my transport object aligns with examples in the nodemailer documentation, I'm at a loss for what else to attempt.

Could the use of firebase cloud functions be contributing to this issue?

Answer №1

Resolved by modifying the import statement to

import * as nodemailer from 'nodemailer';

and changing it to

const nodemailer = require('nodemailer');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error TS2339: The type 'never' does not have the property 'getBoundingClientRect'

While optional chaining should suffice, I may have gone a bit overboard in attempting to satisfy TypeScript: const ref = useRef() if (ref !== undefined) { if(ref.hasOwnProperty('current')) { if (ref.current !== undefined ...

A SyntaxError was caught due to an unexpected token '<' in the constants.js file when using react and vite

I'm trying to display a button in the sidebar with a name and an icon. I've been iterating through the list of categories, which are imported from the 'constants.js' file located in the utils folder. However, instead of getting the desi ...

Guide to making a dynamic clip mask with flowing trails on a digital canvas

I have successfully coded a dynamic path with trails similar to the one shown on However, when I try to replace ctx.fill() with ctx.clip(), nothing appears on the canvas. Here is the JavaScript code snippet I'm using – for the full code, visit http ...

What is the process for curving a cylinder in three.js?

Is there a way to arc or bend a distorted cylinder geometry in three.js? I'm interested in specifying the following parameters: Bend Start - starting point of the bend on the cylinder's height Bend End - ending point of the bend on the cylinde ...

Swap the comma for a period as you type out jQuery code

Hey there, I'm trying to figure out how to use jQuery to replace a comma with a dot while typing in a text input field. Currently, my code looks like this: $(document).on('change', '.unitprice', function() { $(this).val().replac ...

Encountering both a CORS error and data in Angular 7

My application is using Angular 7 for the front end and Node.js (express) for the backend. The cors module in the Node.js server.js file is implemented like this: var cors = require('cors') app.use(cors()); When making an API call from the fro ...

What steps can be taken to retrieve data from a database table using JavaScript?

I am encountering a very peculiar issue. The values that I need are visible when I receive them as a message from the server-web console. However, when I try to retrieve them using a for loop, I encounter an error 05-22 18:58:23.203: I/Web Console(29392): ...

Issue with Vue.js: Textarea not functioning properly within a v-for loop

The v-model value within the v-for loop is not unique. Here is the provided template: <template> <div id="FAQ" v-for="(question, index) in questions.slice().reverse()" :key="index" ...

Creating a new music application and looking for ways to keep track of and update the number of plays for

I'm currently developing a music app and am looking for a way to update the play count every time a user listens to a song for at least 30 seconds. I've attempted the following approach: let current_final; let current_initial; ...

What is the best way to incorporate a subcategory within a string and separate them by commas using Vue.js?

Is it possible to post subcategories in the following format now? Here is the current result: subcategory[] : Healthcare subcategory[] : education However, I would like to have them as a string separated by commas. This is my HTML code: <div id="sub ...

Updating the title in Angular with UI Router when $stateChangeSuccess is triggered too soon?

My implementation of a custom page title follows the ngBoilerplate framework: https://github.com/ngbp/ngbp/blob/v0.3.1-release/src/app/app.js .controller( 'AppCtrl', function AppCtrl ( $scope, $location ) { $scope.$on('$stateChangeSucces ...

Disappearing Image on Hover in JavaScript and HTML

I'm encountering an issue with my JavaScript hover effect on two images. When a user hovers over the arrow image, it should change to a hover version of that image. Additionally, if the user clicks on the arrow, it should trigger another JavaScript fu ...

Having trouble with Node.js POST request; no specific error message displayed

Currently facing a challenge in communicating with an API using nodejs. I've exhausted all possible solutions, including utilizing different request modules and altering the format among other attempts. Here is the code snippet... var request = requ ...

Creating a JavaScript array filled with database data using PHP

Below is a snippet of PHP code used to establish a connection to a database: <?php $host = "localhost"; $user = "admin"; $password = ""; $dbname = "test"; $con = new mysqli($host, $user, $password, $dbname) or die ('Could not connect to the d ...

Determining the name of the currently focused DOM element in Angular2

How can I detect the name of a selected element from a group of select elements on a page? For example: <select (click)="functionDetectName()" name="test1"> <select (click)="functionDetectName()" name="test2"> <select (click)="functionDete ...

How do I create a button that triggers function1 when held for two seconds, but if held for less than two seconds, triggers function2 instead

The button on my device is not functioning properly when I try to hold it for a certain period of time (it acts as if it's being clicked instead). I attempted to implement a feature where if the button is held down for 2 seconds or more, callfunction ...

Adding basic data to an array dynamically

I am interested in creating an array with just one value inside it on the spot without having to use a variable. The following code achieves that using a variable: var arr = []; arr.push('test'); console.log(arr); // correctly logs ["test"] How ...

Vuelidate allows for validation to occur upon clicking a button, rather than waiting for the field

As I navigate my way through learning vuelidate, everything seems to be going smoothly, except for one thing. I can't figure out how to trigger validation only when the "Submit" button is clicked. Currently, the fields turn red as soon as I start typi ...

Glitchy/Crazy CSS3 Animations

Currently, I am developing a website at . One of the features I have implemented is CSS3 transitions for route changes, but this feature only works in Chrome. Here's how the animation works: I apply the .preanimate class to rotate the phasing out di ...

Form serialization causes text inputs to be left blank

I am currently using an ajax/php file uploader that includes additional form fields. The hidden form fields with preset values are being passed without any issues, however, the text fields with user-inputted values are coming up empty. Upon checking with h ...