努力配置nodemailer以将gmail与oAuth2一起使用

The*_*Svz 0 javascript gmail smtp typescript nodemailer

我已经按照本教程使用 gmail 设置了 nodemailer。

我的传输器配置如下:

const transportObj = {
  host: 'smtp.gmail.com',
  port: 465,
  secure: true,
  auth: {
    type: "OAuth2",
    user: "myemail@gmail.com",
    clientId: "xxxxxxxxxxx.apps.googleusercontent.com",
    clientSecret: "xxxxxxxx",
    refreshToken: "xxxxxxxxx",
    accessToken: "xxxxxxxxxxxxxxx"
  }
};
Run Code Online (Sandbox Code Playgroud)

然而,当

let transporter = nodemailer.createTransport(transportObj);
Run Code Online (Sandbox Code Playgroud)

被调用,我收到错误

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);

Run Code Online (Sandbox Code Playgroud)

我的传输对象似乎与nodemailer 文档中的示例匹配,所以我不确定还可以尝试什么。

注意:这与 firebase 云功能一起使用。这可能是导致问题的原因吗?

The*_*Svz 7

通过更改导入语句来解决

import * as nodemailer from 'nodemailer';
Run Code Online (Sandbox Code Playgroud)

const nodemailer = require('nodemailer');
Run Code Online (Sandbox Code Playgroud)