Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email from gmail api not received but shown in sent folder

I' m using gapi to send 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 = '[email protected]',
        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. 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: [email protected]
To:  [email protected]
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. Feeling More confused.

Edit: I add a 'Cc': field, It is : [email protected](myself), [email protected], [email protected], [email protected] . All the other guys(Gmail and other mailboxs) received the mail, but I still couldn't receive the mail from myself.

The original mail I received in [email protected] is as follow:

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 <[email protected]>; 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: [email protected]
Date: Wed, 9 Jul 2014 19:38:56 -0700
Message-ID: <CADOxe9KF+VjMFw1bSkFd09RVsa7c7-pz9OguCFovOUemW4ZZbg@mail.gmail.com>
Subject: Hello World
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Content-Type: text/plain; charset=UTF-8
X-CM-TRANSID:XMCowEAJvlfC_L1TjzExBg--.81S3
Authentication-Results: mx42; spf=pass [email protected]; dki
m=pass [email protected]
X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73
VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxUSeT5DUUUU

send a Gmail.

Edit: the original mail in [email protected] is as follow:

Delivered-To: [email protected]
Received: by 10.194.121.101 with SMTP id lj5csp1399131wjb;
    Wed, 9 Jul 2014 19:38:58 -0700 (PDT)
Return-Path: <[email protected]>
Received-SPF: pass (google.com: domain of [email protected] 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 [email protected] designates 10.224.137.9 as             permitted sender) [email protected];
   dkim=pass [email protected]
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: [email protected]
Date: Wed, 9 Jul 2014 19:38:56 -0700
Message-ID: <CADOxe9KF+VjMFw1bSkFd09RVsa7c7-pz9OguCFovOUemW4ZZbg@mail.gmail.com>
Subject: Hello World
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Content-Type: text/plain; charset=UTF-8

send a Gmail.
like image 839
FlyingHorse Avatar asked Jul 10 '14 02:07

FlyingHorse


People also ask

Why are my emails showing as sent but not delivered?

This can be caused by invalid addresses (domain name doesn't exist, typos, changed address, etc.). A soft bounce is an email that gets as far as the recipient's mail server (it recognizes the address) but is bounced back undelivered before it gets to the recipient.

Why are my sent Gmail emails not being received?

The recipient never got the email you sent If the email isn't there, you might have deleted it before you sent it. Ask the recipient to check their Junk or Spam. If it's there, have them add you to their contacts so the next email goes through. Wait a few hours to see if you get a delivery error message.

Why is Gmail showing sent in Inbox?

If you have a Gmail filter set up to send all emails from yourself to your Inbox folder, then that's why sent email show up in the Inbox. Another possible cause is that you have all emails from yourself set up to be marked as starred emails while having all starred messages included in your Primary folder.


1 Answers

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. You only get one copy of the mail, that's the same irregardless of API or using web UI. The problem is that the web UI also puts that message in INBOX as well as 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.)

like image 107
Eric D Avatar answered Nov 06 '22 13:11

Eric D