1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Gmail APIでメールを検索する

Posted at

目的

PostmanからGmail APIをつかってメールを検索し、特定のメールの詳細を表示したい

さてやるか、その前に

PostmanでGmail APIどうやって使うの、はこちらの記事を参照されたし:PostmanでGmailを取得する

さてやるか

今回使うGoogle API

今回使うのは、以下のメソッド:

手順としては、users.messages.listで検索し、ヒットしたメールのIDを使ってusers.messages.getで詳細を表示する感じ。

検索ってどうするの

users.messages.listにはqというパラメータが定義されていて、ここに検索条件をぶっこみます。
説明文コピペしとくか

document.txt
Only return messages matching the specified query. 
Supports the same query format as the Gmail search box. 
For example, "from:someuser@example.com rfc822msgid:<somemsgid@example.com> is:unread". 
Parameter cannot be used when accessing the api using the gmail.metadata scope.

例えば、Findyから送信されたメッセージの一覧を取得したいときには
from:support@findy-code.io
とパラメータを設定する。
また、そのなかから企業が自分に興味を持っているメールだけを取得したいときには
from:support@findy-code.io subject:さんに興味を持っています【Findy】
とパラメータを設定する。

mail_search1.jpg

オマケ:取得したメール一覧のそれぞれに対して、メール詳細を取得する

前回同様、リポジトリにcollectionファイルを配置した(リポジトリ)。
mail_search2.jpg

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?