Gmail API会删除邮件部分

时间:2017-01-26 01:22:26

标签: ruby gmail-api

当我使用Gmail API发送带附件的邮件时,收件人会收到没有附件的邮件。 但奇怪的是: 1:在发件人的已发送文件夹中,我确实看到了附件 2:如果我发送给自己,两条消息都很好(在发送文件夹和收件箱文件夹中) 3:如果我使用带有相同原始消息的GMail SMTP,它可以正常工作 4:如果我使用具有相同原始消息的第三方SMTP,则可以正常工作。

点数1 + 2超级令人费解。

以下是已发送文件夹中原始邮件的来源:

Received: from 13936824666 named unknown by gmailapi.google.com with HTTPREST; Wed, 25 Jan 2017 18:44:30 -0500
Date: Wed, 25 Jan 2017 18:44:30 -0500
From: Jeremy Chatelaine <source@gmail.com>
To: Jeremy <target@domain.com>
Message-Id: <CABX8Avad0vTtu8=jotRD5HM1r0My-ZKeV7RFRo0TmTxf5PNd0g@mail.gmail.com>
Subject: Export
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="--==_mimepart_5889385be5066_a133fd0f785e20837629"; charset=UTF-8
Content-Transfer-Encoding: 7bit

----==_mimepart_5889385be5066_a133fd0f785e20837629
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Please find attached the message


----==_mimepart_5889385be5066_a133fd0f785e20837629
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

Please find attached the message
----==_mimepart_5889385be5066_a133fd0f785e20837629
Content-Type: text/csv; charset=UTF-8; filename=export.csv
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=export.csv
Content-ID: <5889385be6fd7_a133fd0f785e20837735@jeremy.mail>

Some text...

----==_mimepart_5889385be5066_a133fd0f785e20837629--

以下是收件人收件箱文件夹中原始邮件的来源:

Delivered-To: target@domain.com
Received: by 10.55.110.193 with SMTP id j184csp1999707qkc;
        Wed, 25 Jan 2017 16:30:42 -0800 (PST)
X-Received: by 10.107.34.213 with SMTP id i204mr540101ioi.203.1485390642385;
        Wed, 25 Jan 2017 16:30:42 -0800 (PST)
Return-Path: <source@domain.com>
Received: from mail-it0-x22b.google.com (mail-it0-x22b.google.com. [2607:f8b0:4001:c0b::22b])
        by mx.google.com with ESMTPS id 88si336719ioq.54.2017.01.25.16.30.42
        for <target@domain.com>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 25 Jan 2017 16:30:42 -0800 (PST)
Received-SPF: pass (google.com: domain of source@domain.com designates 2607:f8b0:4001:c0b::22b as permitted sender) client-ip=2607:f8b0:4001:c0b::22b;
Authentication-Results: mx.google.com;
       dkim=pass header.i=@domain.com;
       spf=pass (google.com: domain of source@domain.com designates 2607:f8b0:4001:c0b::22b as permitted sender) smtp.mailfrom=source@domain.com
Received: by mail-it0-x22b.google.com with SMTP id 203so119411500ith.0
        for <target@domain.com>; Wed, 25 Jan 2017 16:30:42 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=domain.com; s=domain;
        h=from:mime-version:date:message-id:subject:to;
        bh=wx26/V0bJk9VItDp3TAvKl28UAn7IRQq4NITJZDM+Co=;
        b=L3KTzPTCoIJUfAacuJy+PE8jHnY9iwGuXUWSpZzneRs5bvMysigSMyPGn1YicyIvQ6
         d/LvbEJPlsu+S0zElhIVPITjAmXKDKNIKwLQDHpkcKnnI3btBUrENN923fMtS1fDdHyV
         3At0QenKrb34uQqYYoHtX2WU4nyYrISbYKL62=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:mime-version:date:message-id:subject:to;
        bh=wx26/V0bJk9VItDp3TAvKl28UAn7IRQq4NITJZDM+Co=;
        b=tGPSHjI3iRzjrI0jGHVX76uTw7OXYC4B2bP0qQKgQotBWru+Pn5Ci9A1Qop9oGN1Ys
         fnxCgLOLG8ZJU165ODBNX1DGjPa8ud9SWg18FTsxIjNw9qTr1yJqbWr0LToJi7HdQUr8
         7Aaiqil7PbPUf5SdxLCqwBNf660Rn9Sd/ADZeT1Bc2+iYQcizjiK/rOPPX+X1ZndvqxP
         Ok3Ac2yyIWxi+m4xaPEztcF4JXFZDlJWFdclUDv4s5Jdc0eb1HmB5d2r1qroGLo5MTjd
         d7jO1nRsKTO5I9I69p9AgC+LpDiWBxgzZMBVsU6vVpeZ03/pCroyk9DHDUAjn3ijtlFh
         O2vw==
X-Gm-Message-State: AIkVDXJo2tPJlkHkthgEjnxYp7vz5Rfpn91pWCS7zEurkSiDhJtyzLpUoSDORq37K/7ATCRSyLAypKIYrdYwEiL2
X-Received: by 10.36.84.148 with SMTP id t142mr20263701ita.90.1485390641934; Wed, 25 Jan 2017 16:30:41 -0800 (PST)
Received: from 13936824667 named unknown by gmailapi.google.com with HTTPREST; Wed, 25 Jan 2017 19:30:41 -0500
From: Jeremy Chatelaine <source@domain.com>
Mime-Version: 1.0
Date: Wed, 25 Jan 2017 19:30:41 -0500
Message-ID: <CABK5xHonVstaJHWHfvBJFF1BK5Y0B8NJsAJTPFokPNAUcawhGA@mail.gmail.com>
Subject: Export
To: Jeremy <target@domain.com>
Content-Type: multipart/alternative; boundary=001a1143a6cc90c9040546f4753f

--001a1143a6cc90c9040546f4753f
Content-Type: text/plain; charset=UTF-8

Please find attached your requested export

--001a1143a6cc90c9040546f4753f
Content-Type: text/html; charset=UTF-8

Please find attached your requested export

--001a1143a6cc90c9040546f4753f--

正如你所看到的,我文字附件的哑剧部分消失了。

以下是消息的生成方式(为清晰起见而剪切)

msg = Mail.new
html_part = Mail::Part.new do
    content_type 'text/html; charset=UTF-8'
    body html_body
end

msg.html_part = html_part

new_text = plan_text
text_part = Mail::Part.new do
    body new_text
end
msg.text_part = text_part

file_paths.each do |file_path|
    msg.add_file(file_path)

    # I also tried like that, same result
    #open(file_path) do |file| 
    #   msg.attachments[file_path] = file.read 
    #end
end
raw_message = msg.to_s

以下是我使用gmail api发送的方式

client = Google::APIClient.new(:application_name => "app", :application_version => "1")

client.authorization.client_id = "someverylongnumbers.apps.googleusercontent.com"
client.authorization.client_secret = "morerandomletters"
client.authorization.access_token = token
client.authorization.scope = [
    "https://www.googleapis.com/auth/gmail.modify"
]

gmail_api = client.discovered_api('gmail', 'v1') # https://www.googleapis.com/auth/gmail.modify

result = client.execute(
    :api_method => gmail_api.users.messages.to_h['gmail.users.messages.send'],
    :parameters => {
        'userId' => "me"
    },
    :body_object => {
        'raw' =>  Base64.urlsafe_encode64(raw_message)
    }
)

这有什么问题?

0 个答案:

没有答案