2017年1月21日土曜日

簡単にGmailの下書きを作れるGemを作ったお

GmailApiJp
https://github.com/kenta-s/gmail_api_jp

GmailのAPIを使っていろいろできるんだけども、
少し難しかったり日本語を使う場合は特別な処理が必要だったりして大変なので、
簡単に扱えるGemを作りました。

いまのところ下書きを作成するだけですが、必要に迫られたら拡張していく予定です。

使い方

まずはアプリケーションを認証しないといけないので、こちらを参考にclient_secret.jsonを用意してください
https://developers.google.com/gmail/api/quickstart/ruby

そしてgem install
$ gem install gmail_api_jp

gmail_draft.ymlというファイルを配置(通常はアプリケーションのルートディレクトリ)して、
中身はこんな感じ
application_name: 認証時に入力したアプリケーション名 
client_secrets_path: "/Path/to/your/client_secret.json"


下書きにしたいメールのテキストを変数なりに準備して
text =<<TEXT
To: foo@example.com
Cc: bar@example.com, baz@example.com
Subject: こんにちは

こんにちは
ご機嫌いかがですか
TEXT

draft = GmailApiJp::Draft.new(text)
draft.create_draft
で、Gmailにログインすると下書きができているはず。

※初回のGmailApiJp::Draft.new時はアプリケーションを認証するために対話モードでトークンの入力を求められます。
指示に従って認証してください。

Issue, PRまってます

2 件のコメント:

  1. online casino no deposit bonus | Agen Judi Slot Gacor Terpercaya
    Playtech is a provider of casino games with a wide range of 우리카지노 slots and 온카지노 jackpots. This online 더킹카지노 casino is regulated in Curacao with a strict no-

    返信削除
  2. Harrah's Atlantic City, NJ - Mapyro
    Find your way around the casino, find 여주 출장마사지 where everything 전라남도 출장안마 is 경주 출장샵 located, and get directions, reviews, and information for Harrah's Atlantic 영천 출장마사지 City 남양주 출장안마 in New Jersey.

    返信削除