如何解决努力配置 nodemailer 以将 gmail 与 oAuth2
我已关注 this tutorial 以使用 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"
}
};
然而,当
let transporter = nodemailer.createTransport(transportObj);
被调用,我收到错误
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);
我的传输对象似乎与 nodemailer documentation 中的示例相匹配,所以我不确定还可以尝试什么。
注意:这与 firebase 云功能一起使用。这可能是导致问题的原因吗?
解决方法
通过更改import语句解决
import * as nodemailer from 'nodemailer';
到
const nodemailer = require('nodemailer');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。