从gmail发送电子邮件api未收到,但显示在已发送文件夹



我正在使用gapi发送gmail。但如果我把邮件发给自己,它就不会出现在我的收件箱里。最奇怪的是,它出现在"发送"文件夹中。'

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'rn"+
        "To:  "+ to +"rn"+
        "Subject: "+subject+"rn"+
        "rn"+
        content;
    sendMessage(email, function () {
        console.log(arguments);
    });
}

'控制台的信息日志为:

"[↵ {↵  "id": "gapiRpc",↵  "result": {↵   "id": "1471e09d88000bf7",↵   "threadId": "1471e09d88000bf7",↵   "labelIds": [↵    "SENT"↵   ]↵  }↵ }↵]↵"

我可以在Gmail的"已发送"文件夹中看到这封邮件,但我没有在收件箱中看到它。"已发送"文件夹中此邮件的原件如下:

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.

有人知道为什么吗?非常感谢!

编辑:我将Mime邮件中的"收件人"改为另一个邮箱(不是Gmail),并正确收到邮件。感觉更困惑了。

编辑:我添加了一个"抄送":字段,它是:znlswd@gmail.com(我自己),71848140@qq.com, swdpal2014@gmail.com, ezdiary@163.com。所有其他人(Gmail和其他邮箱)都收到了邮件,但我仍然收不到我自己的邮件。

我在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.

编辑: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.

所以要清楚,发送邮件的工作方式是正确地发送给其他人。在给自己发邮件的情况下(你为什么要这样做?是否真的需要这样,而不是仅仅使用messages.insert?),那么它只出现在SENT标签中,而不出现在INBOX标签中。你只得到一个邮件副本,不管API还是使用web UI都是一样的。问题是,web UI也将该消息放在INBOX和SENT中。(正如您所看到的,发送给自己是一个有点特殊的情况,因为诸如基于Message-Id头的欺骗检测等)

自己回答这个问题。首先,我尝试使用messages.insert。但是,如果我将"发件人"设置为"收件人"(我的电子邮件地址),那么邮件仍然只会在"发送"文件夹中。正确的方法是利用信息。修改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);
     }
})

messageid指的是发送api返回的id。

一个未经测试的想法:您可以尝试在messages.send REST调用中添加X-Gmail-Labels: Inbox标头,希望Gmail会添加标签。我是在Google将GMail中的一些标签移出到mbox文件时看到这个头文件的

相关内容

  • 没有找到相关文章

最新更新