【发布时间】:2021-04-09 05:21:18
【问题描述】:
我希望有人可以帮助我。
我正在使用 nodejs 和 Nodemailer 连接到公司 g-suite 帐户,我想从该帐户自动从地址 info@domain.com 发送电子邮件。
按照https://medium.com/@imre_7961/nodemailer-with-g-suite-oauth2-4c86049f778a 中的说明进行操作
我在 azure 函数中有以下代码。
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
const YOUR_EMAIL_ADDRESS = 'cesarcas@delfometrics.com';
const YOUR_EMAIL_ADDRESS_AUTOMATIC_SENDER = 'info@delfometrics.com';
// Change this to the receiver to the mail
const SEND_TO = (req.query.toemail || (req.body && req.body.toemail));
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: YOUR_EMAIL_ADDRESS,
serviceClient: "bla bla bla private",
privateKey: "bla blab bla private",
},
});
try {
await transporter.verify();
await transporter.sendMail({
from: YOUR_EMAIL_ADDRESS_AUTOMATIC_SENDER ,
to: SEND_TO,
subject: 'John Doe opens new farm YOU GOTTA SEE IT',
text: 'It is beautiful 2.',
});
context.res = {
// status: 200, /* Defaults to 200 */
body: "already send email"
};
} catch (err) {
context.log(err);
}
}
我的问题是:
只有用户帐户使用服务帐户,而不是群组电子邮件。
我已经按照说明在 google 工作区中配置了一个组:
1- 使用该地址创建一个组,例如:'info@domain.com'
2- 确保该组没有成员(如果您不想收到发送到该地址的电子邮件)
3- 确保该组可以用作电子邮件地址。请谷歌这个,有很多信息。
4- 创建传输时将“cesarcas@domain.com”设置为 auth.user。
5- 现在您可以在发送电子邮件时将发件人字段设置为“info@domain.com”。 ????
即便如此,配置组后,
每次我运行代码时,电子邮件都会正确发送,但不是来自正确的地址
也就是说,虽然我在YOUR_EMAIL_ADDRESS_AUTOMATIC_SENDER 中指定了地址 info@domain.com,但它从YOUR_EMAIL_ADDRESScesarcas@domain.com(这是组织内的正确用户帐户)发送电子邮件,看起来像来自 nodemailer 库的错误或 google 工作区中的组配置问题。
非常感谢您的帮助
【问题讨论】:
标签: nodemailer google-workspace