我正在尝试将 gmail smtp 与最新版本的 nodemailer 一起使用。我已完成此处描述的步骤。发送邮件时我仍然收到以下错误消息:
错误:无效登录:535-5.7.8 用户名和密码不被接受
这很奇怪,因为我从未尝试使用密码/用户名登录,但我使用 OAuth2 代替:
transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: 'hello@company.com',
clientId: '<clientId>.apps.googleusercontent.com',
clientSecret: '<clientSecret>',
accessToken: '<accessToken>',
refreshToken: '<refreshToken>',
}
});
transporter.sendMail({
from: from,
to: to,
subject: subject,
text: message,
html: htmlMessage
}, function (err, data) {
if (err) {
console.log(err);
console.log("======");
console.log(subject);
console.log(message);
} else {
console.log('Email sent:');
console.log(data);
}
});
Run Code Online (Sandbox Code Playgroud)
有谁知道我错过了什么?我尝试执行所有这些步骤来生成这些令牌 3 次,所以我很确定所有凭据都已正确填写。
提前致谢
我正在尝试使用 POST 方法使用 gmail API 和 POSTMAN 发送邮件
POST https://www.googleapis.com/upload/gmail/v1/users/example@gmail.com/messages/send
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument"
"message": "Recipient address required"
}
],
"code": 400,
"message": "Recipient address required"
}
}
Run Code Online (Sandbox Code Playgroud)
标头已放入内容类型:message/rfc822
我知道这必须编码成base64(web_safe),所以我翻译了
"From: sender.example@gmail.com\r\n" +
"To: receiver.example@gmail.com\r\n" +
"Subject: Subject Example\r\n" +
"This is content: hope you got it\r\n"
Run Code Online (Sandbox Code Playgroud)
我也将它们替换为网络安全
replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
Run Code Online (Sandbox Code Playgroud)
所以我得到了如下的base64。所以我把 raw 放在 POST METHOD 的正文中
{
"raw": "RnJvbTogc2VuZGVyLmV4YW1wbGVAZ21haWwuY29tDQpUbzogcmVjZWl2ZXIuZXhhbXBsZUBnbWFpbC5jb20NClN1YmplY3Q6IFN1YmplY3QgRXhhbXBsZQ0KVGhpcyBpcyBjb250ZW50OiBob3BlIHlvdSBnb3QgaXQNCg"
}
Run Code Online (Sandbox Code Playgroud)
我在谷歌开发者网站上使用了“尝试这个API”,我可以发送它。 https://developers.google.com/gmail/api/v1/reference/users/messages/send
但对于邮递员,我不能。
有什么帮助吗?
我无法找到我的 Gmail 帐户的 userId 来使用 Gmail API。所以有人可以找到。你能告诉我吗?
我正在研究 Gmail API。假设我有兴趣查看哪封邮件包含字符串“foobar2000”。
到目前为止,这是我的代码:
主程序.java
package manhattan.email.bot;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.services.gmail.model.Message;
import com.google.api.services.gmail.model.MessagePart;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.Properties;
import manhattan.email.bot.google.GmailCredentials;
import manhattan.email.bot.google.GmailService;
import manhattan.email.bot.google.GmailServiceImpl;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
public class Main {
static final String MY_EMAIL = "xxxxx@gmail.com";
static final String MY_CLIENT_ID = "xxxxxapps.googleusercontent.com";
static final String MY_CLIENT_SECRET = "xxxxx";
static final String MY_ACCESS_TOKEN = "xxxxx";
static final String MY_REFRESH_TOKEN = "xxxxx";
public static void main(String[] args) {
try {
GmailService gmailService = …Run Code Online (Sandbox Code Playgroud) 正如标题所述,是否有人成功为通过gmail api发送的电子邮件启用了 3 种安全机制?
目前,我通过 gmail-api (http) 发送的所有电子邮件均已被收件人成功接收,但没有任何安全标记。这适用于我们的 chrome 扩展和 gmail-addon。
我正在尝试使用 Gmail API 发送电子邮件。但我收到这个错误
googleapi:错误 403:请求的身份验证范围不足。更多详细信息:原因:权限不足,消息:权限不足
我认为这可能与配置有关,我还遵循了 google 的 Go 快速入门,这里是 getClient 函数:
func getClient(config *oauth2.Config) *http.Client {
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
tokFile := "token.json"
tok, err := tokenFromFile(tokFile)
if err != nil {
tok = getTokenFromWeb(config)
saveToken(tokFile, tok)
}
return config.Client(context.Background(), tok)
}
Run Code Online (Sandbox Code Playgroud)
这是发送的代码:
case "pass":
templateData := struct {
VerPass string
}{
VerPass: cont1,
}
emailBody, …Run Code Online (Sandbox Code Playgroud) 我们通过 Gmail API 应用程序发送的所有电子邮件都存在问题。所有邮件都附带有关电子邮件安全的警告
这条消息看起来很危险。许多人将类似的邮件标记为网络钓鱼诈骗,因此这可能包含不安全的内容。避免点击链接、下载附件或回复个人信息。

仅当通过我们发送电子邮件时才会发生这种情况Gmail API,但通过发送电子邮件时SMTP将在没有任何警告的情况下传递消息。
此警告消息会出现在通过我们的 Gmail API 应用程序发送的所有电子邮件上,无论发件人是 Google Workspace 用户还是免费 Gmail 用户。
有人可以帮忙吗?
google-api-client我一直在开发一个小项目,该项目连接到用户的 Gmail 收件箱并使用2.0.0 和google-api-services-gmail版本 v1-rev20220404-2.0.0读取邮件
当我尝试构建 Gmail 服务时
service = new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY,
authorize).setApplicationName(Main.APPLICATION_NAME).build();
Run Code Online (Sandbox Code Playgroud)
它抛出一个 IllegalStateException 说
“您当前运行的是 2.0.0 版的 google-api-client。您至少需要 1.15 版的 google-api-client 才能运行 1.25.0 版的 Gmail API 库。”
起初我以为可能是我安装的模块不是最新的或者什么的,但这并没有真正意义,所以我尝试调试并进入了 Gmail.java 类。
该代码以非常简单的方式检查版本,如果条件为 false,则抛出异常
static {
Preconditions.checkState(GoogleUtils.MAJOR_VERSION == 1 && GoogleUtils.MINOR_VERSION >= 15,
"You are currently running with version %s of google-api-client. You need at least version 1.15 of google-api-client to run version 1.25.0 of the Gmail API library.",
new Object[]{GoogleUtils.VERSION});
}
Run Code Online (Sandbox Code Playgroud)
我认为这就是问题所在,我的 MAJOR_VERSION 为 2 …
我希望与 Gmail API 集成,并希望使用具有全网域委托的服务用户来代表 Google Workspaces 中的用户请求数据。我的代码在AWS的EC2中运行。通读文档,最佳实践似乎是使用工作负载身份联合来作为服务用户进行身份验证,这样就不存在密钥泄露的风险。
我已按照Google 网站上的步骤设置与 AWS 的工作负载身份联合,此外,还在 google cloud shell 中运行以下命令:
gcloud iam service-accounts add-iam-policy-binding <service_account_email> \
--role=roles/iam.workloadIdentityUser \
--member="principalSet://iam.googleapis.com/projects/<project_id>/locations/global/workloadIdentityPools/<pool_id>/attribute.aws_role/arn:aws:sts::<aws_account_id>:assumed-role/<aws_role_name>" \
--project <google_cloud_project_name>
Run Code Online (Sandbox Code Playgroud)
我有以下测试应用程序代码:
const { google } = require("googleapis");
const { GoogleAuth } = require("google-auth-library");
const path = require("path");
module.exports = async (req, res) => {
const scopes = [
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/admin.directory.user.readonly",
];
let status = "";
try {
//Inject the client library config as the GOOGLE_APPLICATION_CREDENTIALS
const configPath = path.join(__dirname, "client_library_config.json");
process.env["GOOGLE_APPLICATION_CREDENTIALS"] = …Run Code Online (Sandbox Code Playgroud) amazon-web-services node.js google-cloud-platform gmail-api workload-identity
大约一周前,我在谷歌上设置了一个应用程序。现在,当我尝试运行时:
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
creds = None
if os.path.exists('token.pickle'):
with open(self.CREDENTIALS_PATH+self.conjoiner+'token.pickle', 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request()) ##error here
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Exception has occurred: RefreshError
('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?
python google-api google-oauth google-api-python-client gmail-api
gmail-api ×10
google-api ×5
gmail ×4
google-oauth ×2
java ×2
node.js ×2
gmail-addons ×1
go ×1
nodemailer ×1
postman ×1
python ×1