我想询问有关nodemailer的一些信息,我会像
那样编写代码Var client = nodemailer.createTransport ({
Service: 'gmail',
Auth: {
User: 'example@gmail.com', // Your email address
Pass: '123' // Your password},
Tls: {rejectUnauthorized: false}
});
这样可行,但在成功发送后,当我必须接收已发送的电子邮件时,我需要启用gmail设置,例如"允许不太安全的应用访问"。我不想设置它。
那么如何从example@gmail.com发送电子邮件到example1@gmail.com,而不设置"允许安全性较低的应用访问"和邮件直接在邮箱中接受!! ???或者任何其他应该添加的插件??
THANX;)
答案 0 :(得分:2)
获取accessToken&来自Google OAuth2.0 Playground的refreshToken, clientId&来自Google开发者控制台的clientSecret
if (vars.get("JMeterThread.last_sample_ok") == "false") {
....
}
答案 1 :(得分:0)
您需要获取访问令牌,不能静态提供。 googleapis 可以是 gmail 的用户。 例如:
const { google } = require('googleapis');
const { OAuth2 } = google.auth;
const {
MAILING_SERVICE_CLIENT_ID,
MAILING_SERVICE_CLIENT_SECRET,
MAILING_SERVICE_REFRESH_TOKEN,
SENDER_EMAIL_ADDRESS,
OAUTH_PLAYGROUND //https://developers.google.com/oauthplayground
} = process.env;
const oauth2Client = new OAuth2(
MAILING_SERVICE_CLIENT_ID,
MAILING_SERVICE_CLIENT_SECRET,
OAUTH_PLAYGROUND
);
oauth2Client.setCredentials({
refresh_token: MAILING_SERVICE_REFRESH_TOKEN,
});
//>>> get the accessToken
const accessToken = oauth2Client.getAccessToken();
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: SENDER_EMAIL_ADDRESS,
clientId: MAILING_SERVICE_CLIENT_ID,
clientSecret: MAILING_SERVICE_CLIENT_SECRET,
refreshToken: MAILING_SERVICE_REFRESH_TOKEN,
accessToken,
},
});
let mailOptions = {
from: 'no-reply@blah.com',
to: 'to_blah@blah.com',
subject: 'test',
text: 'test'
};
let result = await transporter.sendMail(mailOptions);