【发布时间】:2020-12-19 16:22:59
【问题描述】:
我已在我的 Gsuite 管理面板中将 no-reply@domain.com 设置为电子邮件组。现在我想使用我正在使用 nodemailer 的节点 js 中的那个电子邮件地址发送一封电子邮件。为此,我在 Google Cloud 中创建了服务帐户并将 no-reply@domain.com 组添加为所有者。问题是当我在我的节点应用程序中使用这些生成的凭据时,它会抛出一个错误unauthorized_client。
我在 Gsuite 的 API 权限中添加了 client_id 和所需的 GMAIL 范围。只有用户帐户使用服务帐户,而不是群组电子邮件。
这是我的示例 nodemailer 代码
const smtpTransport = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: "OAuth2",
user: "no-reply@domain.com",
serviceClient: "109120716xxxxxxxxxxxxxx",
privateKey: "",
}
});
我正在按照这个教程来实现这个https://medium.com/@imre_7961/nodemailer-with-g-suite-oauth2-4c86049f778a
【问题讨论】:
-
您未能正确设置 G Suite 域范围委派。使用有关如何设置委派的详细信息编辑您的问题。我不推荐那篇文章中的方法,因为这些凭据有太多的权力。他们对您的整个 G Suite 帐户拥有管理员权限。相反,创建一个用户登录并使用
username/password或username/token发送电子邮件。 -
@JohnHanley 你的意思是我应该为
no-reply@domain.com拥有单独的电子邮件帐户而不是群组电子邮件? -
是的,您应该使用/创建一个 G Suite 电子邮件帐户。然后使用这些凭据发送电子邮件。您正在尝试在您的问题中使用模拟。我不确定“no-reply@domain.com
. Typically that is a non-existant email address. That has nothing to do with Domain Wide Delegation (account impersonation). However, I just realized that you are trying to impersonateno-reply@domain.com”是什么意思。那个账户存在吗?否则,您无法模拟不存在的帐户。 -
确保您了解使用“无回复”地址所做的事情。了解用于向 G Suite 进行身份验证的身份与回复电子邮件地址不同。它们可以相同或不同。如果您不想被“阻止/列入黑名单”,则必须处理退回、拒绝、投诉等。 help.returnpath.com/hc/en-us/articles/…glockapps.com/blog/bounce-email-handling
标签: google-cloud-platform nodemailer google-workspace service-accounts