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

时间:2014-07-10 02:18:25

标签: javascript google-api gmail gmail-api

我'使用gapi发送gmail。但是,如果我将邮件发送给自己,它就不会出现在我的收件箱中。最奇怪的是,它出现在'已发送的#39;夹。 `

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);
    });
}

` 控制台中的信息日志是:

"[↵ {↵  "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.

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

编辑: 我改变了:&#39; To:&#39;在Mime消息中到另一个邮箱(而不是Gmail),并正确接收邮件。感觉更困惑。

编辑: 我添加了一个&#39; Cc&#39;:字段,它是: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.

3 个答案:

答案 0 :(得分:1)

所以要明确的是,发送邮件的工作正常,因为它正确地发送给其他人。在向自己发送邮件的情况下(为什么你要这样做?这真的需要,而不是仅仅使用messages.insert吗?)然后它只出现在SENT但不是INBOX标签。您只能获得一份邮件副本,无论是API还是使用Web UI都是如此。问题是Web UI还将该消息放入INBOX和SENT中。 (正如您所知,由于基于Message-Id标头的欺骗检测等问题,发送给自己有点特殊情况。)

答案 1 :(得分:0)

自己回答这个问题。首先,我尝试使用messages.insert。但是,如果我将“发件人”设置为与“收件人”(我的电子邮件地址)相同,则邮件仍然只会位于“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);
     }
})

'messageid'指的是send api返回的id。

答案 2 :(得分:0)

未经考验的想法:您可以尝试在X-Gmail-Labels: Inbox REST通话中添加messages.send标头,希望Gmail能够添加标签。我在GMail中将一些标签用于mbox文件时,我看到了这个标题。