[英]Sending email from gmail api not received but shown in sent folder
I' m using gapi to send gmail. 我正在使用gapi发送gmail。 But if I send the mail to myself, it doesn't appear in my inbox.
但是,如果我将邮件发送给自己,它不会出现在我的收件箱中。 The most strange, it appears in the 'Sent' folder.
最奇怪的是,它出现在“已发送”文件夹中。 `
`
function sendMessage(email, callback) {
// Web-safe base64
var base64EncodedEmail = btoa(email).replace(/\//g,'_').replace(/\+/g,'-');
var request = gapi.client.gmail.users.messages.send({
'userId': 'me',
'message': {
'raw': base64EncodedEmail
}
});
request.execute(callback);
}
function send() {
var var to = 'znlswd@gmail.com',
subject = 'Hello World',
content = 'send a Gmail.'
var email = "From: 'me'\r\n"+
"To: "+ to +"\r\n"+
"Subject: "+subject+"\r\n"+
"\r\n"+
content;
sendMessage(email, function () {
console.log(arguments);
});
}
` The information log in console is: `控制台中的信息日志是:
"[↵ {↵ "id": "gapiRpc",↵ "result": {↵ "id": "1471e09d88000bf7",↵ "threadId": "1471e09d88000bf7",↵ "labelIds": [↵ "SENT"↵ ]↵ }↵ }↵]↵"
And I can see this mail in the 'Sent' folder in Gmail, but I didn't get it in the inbox. 我可以在Gmail的“已发送”文件夹中看到此邮件,但我没有在收件箱中看到它。 The original of this mail in the 'Sent' folder is as follow:
“已发送”文件夹中此邮件的原始内容如下:
Received: from 823618323534-124pu7sujfj5olv94rkr0apqdppc6nti.apps.googleusercontent.com
named unknown
by gmailapi.google.com
with HTTPREST;
Wed, 9 Jul 2014 19:11:07 -0700
From: znlswd@gmail.com
To: znlswd@gmail.com
Subject: Hello World
Date: Wed, 9 Jul 2014 19:11:07 -0700
Message-Id: <CADOxe9KLTdYfcb8OxWz+rFSM4tVKuZcVV8HJ4byv95+qPA=+dw@mail.gmail.com>
send a Gmail.
Anybody knows why? 谁知道为什么? Thanks very much!
非常感谢!
Edit: I change the 'To:' in Mime message to another mailbox(not Gmail), and receive the mail correctly. 编辑:我将Mime邮件中的“收件人:”更改为另一个邮箱(而非Gmail),并正确接收邮件。 Feeling More confused.
感觉更困惑。
Edit: I add a 'Cc': field, It is : znlswd@gmail.com(myself), 71848140@qq.com, swdpal2014@gmail.com, ezdiary@163.com . 编辑:我添加一个'Cc':字段,它是:znlswd @ gmail.com(我自己),71848140 @ qq.com,swdpal2014 @ gmail.com,ezdiary @ 163.com。 All the other guys(Gmail and other mailboxs) received the mail, but I still couldn't receive the mail from myself.
所有其他人(Gmail和其他邮箱)收到了邮件,但我仍然无法收到自己的邮件。
The original mail I received in ezdiary@163.com is as follow: 我在ezdiary@163.com收到的原始邮件如下:
Received: from mail-qg0-f44.google.com (unknown [209.85.192.44])
by mx42 (Coremail) with SMTP id XMCowEAJvlfC_L1TjzExBg--.81S3;
Thu, 10 Jul 2014 10:39:03 +0800 (CST)
Received: by mail-qg0-f44.google.com with SMTP id j107so7126918qga.31
for <ezdiary@163.com>; Wed, 09 Jul 2014 19:38:57 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:from:date:message-id:subject:to:cc:content-type;
bh=zgoFEkSzE1bUNp54umXlfaDEDw5bLf2Ei0uFrgrVZic=;
b=UHOLwuTsFL9yajR0nn/TskbhVKrIfzX4OAsNDno4S2QIvwx83H5dOe2WMyFbL6Plmk
n4z2qzGjturoi1411+PGpgj8rt4Y57aDQpu7tEOMolMmFLJomtCSmagHIHhc0qwU+CRL
rTjO2ztwZoj/ejnqwcmANzgzMMnSxxkcIf3OvXhLm+j+5yHQvPhmGWIapFWJaTN+9gb9
Q47Qkqe5dBrsxOnGhgQnr1orbE5NcLIYumZTH1YfCMZvqIjUtmviUQUKpfhNQD5UtCX0
0J2moKK98Q5Vek4Wti/WtnEqOgNTzHkIL1M90eeAJKelyPu4TQ7G9GJxr1FX+s4WhgrM
xTFA==
MIME-Version: 1.0
X-Received: by 10.224.137.9 with SMTP id u9mr78577439qat.24.1404959937414;
Wed, 09 Jul 2014 19:38:57 -0700 (PDT)
Received: from 823618323534-124pu7sujfj5olv94rkr0apqdppc6nti.apps.googleusercontent.com
named unknown by gmailapi.google.com with HTTPREST; Wed, 9 Jul 2014 19:38:56 -0700
From: znlswd@gmail.com
Date: Wed, 9 Jul 2014 19:38:56 -0700
Message-ID: <CADOxe9KF+VjMFw1bSkFd09RVsa7c7-pz9OguCFovOUemW4ZZbg@mail.gmail.com>
Subject: Hello World
To: znlswd@gmail.com
Cc: 71848140@qq.com, swdpal2014@gmail.com, ezdiary@163.com
Content-Type: text/plain; charset=UTF-8
X-CM-TRANSID:XMCowEAJvlfC_L1TjzExBg--.81S3
Authentication-Results: mx42; spf=pass smtp.mail=znlswd@gmail.com; dki
m=pass header.i=@gmail.com
X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73
VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxUSeT5DUUUU
send a Gmail.
Edit: the original mail in swdpal2014@gmail.com is as follow: 编辑:swdpal2014@gmail.com中的原始邮件如下:
Delivered-To: swdpal2014@gmail.com
Received: by 10.194.121.101 with SMTP id lj5csp1399131wjb;
Wed, 9 Jul 2014 19:38:58 -0700 (PDT)
Return-Path: <znlswd@gmail.com>
Received-SPF: pass (google.com: domain of znlswd@gmail.com designates 10.224.137.9 as permitted sender) client-ip=10.224.137.9
Authentication-Results: mr.google.com;
spf=pass (google.com: domain of znlswd@gmail.com designates 10.224.137.9 as permitted sender) smtp.mail=znlswd@gmail.com;
dkim=pass header.i=@gmail.com
X-Received: from mr.google.com ([10.224.137.9])
by 10.224.137.9 with SMTP id u9mr68151154qat.24.1404959937949 (num_hops = 1);
Wed, 09 Jul 2014 19:38:57 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:from:date:message-id:subject:to:cc:content-type;
bh=zgoFEkSzE1bUNp54umXlfaDEDw5bLf2Ei0uFrgrVZic=;
b=UHOLwuTsFL9yajR0nn/TskbhVKrIfzX4OAsNDno4S2QIvwx83H5dOe2WMyFbL6Plmk
n4z2qzGjturoi1411+PGpgj8rt4Y57aDQpu7tEOMolMmFLJomtCSmagHIHhc0qwU+CRL
rTjO2ztwZoj/ejnqwcmANzgzMMnSxxkcIf3OvXhLm+j+5yHQvPhmGWIapFWJaTN+9gb9
Q47Qkqe5dBrsxOnGhgQnr1orbE5NcLIYumZTH1YfCMZvqIjUtmviUQUKpfhNQD5UtCX0
0J2moKK98Q5Vek4Wti/WtnEqOgNTzHkIL1M90eeAJKelyPu4TQ7G9GJxr1FX+s4WhgrM
xTFA==
MIME-Version: 1.0
X-Received: by 10.224.137.9 with SMTP id u9mr78577439qat.24.1404959937414;
Wed, 09 Jul 2014 19:38:57 -0700 (PDT)
Received: from 823618323534-124pu7sujfj5olv94rkr0apqdppc6nti.apps.googleusercontent.com
named unknown by gmailapi.google.com with HTTPREST; Wed, 9 Jul 2014 19:38:56 -0700
From: znlswd@gmail.com
Date: Wed, 9 Jul 2014 19:38:56 -0700
Message-ID: <CADOxe9KF+VjMFw1bSkFd09RVsa7c7-pz9OguCFovOUemW4ZZbg@mail.gmail.com>
Subject: Hello World
To: znlswd@gmail.com
Cc: 71848140@qq.com, swdpal2014@gmail.com, ezdiary@163.com
Content-Type: text/plain; charset=UTF-8
send a Gmail.
So to be clear, sending mail works as it sends correctly to others. 所以要清楚,发送邮件的工作正常,因为它正确地发送给其他人。 In the case of sending mail to yourself (why exactly are you doing this? is this really needed as opposed to say just using messages.insert?) then it appears in only SENT but not also INBOX label.
在向自己发送邮件的情况下(为什么你要这样做?这真的需要,而不是仅仅使用messages.insert吗?)然后它只出现在SENT但不是INBOX标签。 You only get one copy of the mail, that's the same irregardless of API or using web UI.
您只能获得一份邮件副本,无论是API还是使用Web UI都是如此。 The problem is that the web UI also puts that message in INBOX as well as SENT.
问题是Web UI还将该消息放入INBOX和SENT中。 (As you can tell, sending to yourself is a bit of a special case due to things like dupe-detection based on the Message-Id header, etc.)
(正如你所知,由于基于Message-Id标头的欺骗检测等问题,发送给自己有点特殊情况)
Answer the question myself. 自己回答这个问题。 First I tried using messages.insert.
首先,我尝试使用messages.insert。 However, if I set the 'From' the same as the 'To'(my email address), the mail will still only be in the 'SENT' folder.
但是,如果我将“发件人”设置为与“收件人”(我的电子邮件地址)相同,则邮件仍然只会位于“SENT”文件夹中。 the right way is using the message.modify api to add 'INBOX' and 'UNREAD' label to the mail sent.
正确的方法是使用message.modify api为发送的邮件添加“INBOX”和“UNREAD”标签。
gapi.client.request({
path: "gmail/v1/users/me/messages/" + messageid + "/modify",
method: "POST",
body: "{\"addLabelIds\": [\"UNREAD\",\"INBOX\"]}",
callback: function() {
console.log("gmail sent to self");
return console.log(arguments);
}
})
The 'messageid' refer to the id return by the send api. 'messageid'指的是send api返回的id。
An untested idea: you can try adding an X-Gmail-Labels: Inbox
header to the messages.send
REST call in hopes that Gmail will add the label. 一个未经测试的想法:您可以尝试在
messages.send
REST调用中添加X-Gmail-Labels: Inbox
标头,希望Gmail能够添加标签。 I saw this header when doing a Google Takeout of some labels in GMail to mbox files. 我在使用GMail中的一些标签对mbox文件进行Google Takeout时看到了这个标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.