通过 GMail 发送基本电子邮件时参数无效 API
Invalid arguments when sending basic email through GMail API
我正在尝试使用 Gmail API 文档中的示例通过表格中的 Google Apps 脚本通过 Gmail API 发送电子邮件,但我收到了一个:
Exception: Invalid number of arguments provided. Expected 2-4 only (line 240, file "Code").
Line 240
是我调用Gmail.Users.Messages.send
的时候。这看起来是我可以构造的最基本的电子邮件消息。有人可以帮我解决我所缺少的吗?
function senDAMail() {
var bdy = "From: steve@gmail.com\n\r, To: steve@gmail.com\n\r, Subject: test\n\r\n\r, You first build the message with headers like From and Subject as you mentioned, but you have to encode the message before sending it. There is no way around that.";
var encodemsg = Utilities.base64EncodeWebSafe(bdy);
Gmail.Users.Messages.send({
auth: this.oAuth2Client,
'userId': 'steve@gmail.com',
'resource': {
'raw': encodemsg
}
});
}
这个修改怎么样?
修改点:
- 请删除
\n\r, To
、\n\r, Subject
和 \n\r\n\r, YouP
中的 ,
。
- 请将
\n\r
替换为\r\n
或仅替换\n
。
Gmail.Users.Messages.send(resource, userId)
的参数是resource, userId
。
- 在你的情况下,我认为
resource
和 userId
分别是 {raw: encodemsg}
和 "me"
。
当以上几点反映到你的脚本中,就会变成下面这样。
修改后的脚本:
function senDAMail() {
var bdy = "From: steve@gmail.com\nTo: steve@gmail.com\nSubject: test\n\nYou first build the message with headers like From and Subject as you mentioned, but you have to encode the message before sending it. There is no way around that.";
var encodemsg = Utilities.base64EncodeWebSafe(bdy);
Gmail.Users.Messages.send({raw: encodemsg}, "me");
}
参考:
如果这不能直接解决您的问题,我深表歉意。
我正在尝试使用 Gmail API 文档中的示例通过表格中的 Google Apps 脚本通过 Gmail API 发送电子邮件,但我收到了一个:
Exception: Invalid number of arguments provided. Expected 2-4 only (line 240, file "Code").
Line 240
是我调用Gmail.Users.Messages.send
的时候。这看起来是我可以构造的最基本的电子邮件消息。有人可以帮我解决我所缺少的吗?
function senDAMail() {
var bdy = "From: steve@gmail.com\n\r, To: steve@gmail.com\n\r, Subject: test\n\r\n\r, You first build the message with headers like From and Subject as you mentioned, but you have to encode the message before sending it. There is no way around that.";
var encodemsg = Utilities.base64EncodeWebSafe(bdy);
Gmail.Users.Messages.send({
auth: this.oAuth2Client,
'userId': 'steve@gmail.com',
'resource': {
'raw': encodemsg
}
});
}
这个修改怎么样?
修改点:
- 请删除
\n\r, To
、\n\r, Subject
和\n\r\n\r, YouP
中的,
。 - 请将
\n\r
替换为\r\n
或仅替换\n
。 Gmail.Users.Messages.send(resource, userId)
的参数是resource, userId
。- 在你的情况下,我认为
resource
和userId
分别是{raw: encodemsg}
和"me"
。
- 在你的情况下,我认为
当以上几点反映到你的脚本中,就会变成下面这样。
修改后的脚本:
function senDAMail() {
var bdy = "From: steve@gmail.com\nTo: steve@gmail.com\nSubject: test\n\nYou first build the message with headers like From and Subject as you mentioned, but you have to encode the message before sending it. There is no way around that.";
var encodemsg = Utilities.base64EncodeWebSafe(bdy);
Gmail.Users.Messages.send({raw: encodemsg}, "me");
}
参考:
如果这不能直接解决您的问题,我深表歉意。