トップ «前の日記(2013-08-20) 最新 次の日記(2013-08-22)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|

2013-08-21 :-(

_ 午前

0600 起床

0620 筋トレ

0900 出勤 && 自習

_ 午後

1300 自習

_

1800 退勤

1830 打ち上げ

_ [ruby][gmail][ruby-gmail]ruby-gmail でメール送信する

dcparker/ruby-gmail

基本的には Example Code: のそのままなのだけど、1 つだけ注意。

% ruby send5.rb
/usr/lib/ruby/1.9.1/net/imap.rb:1141:in `get_tagged_response':  Application-specific password required: http://support.google.com/accounts/bin/answer.py?answer=185833 (Failure) (Net::IMAP::NoResponseError)
        from /usr/lib/ruby/1.9.1/net/imap.rb:1195:in `block in send_command'
        from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
        from /usr/lib/ruby/1.9.1/net/imap.rb:1177:in `send_command'
        from /usr/lib/ruby/1.9.1/net/imap.rb:419:in `login'
        from /usr/lib/ruby/gems/1.9.1/gems/ruby-gmail-0.3.0/lib/gmail.rb:95:in `login'
        from /usr/lib/ruby/gems/1.9.1/gems/ruby-gmail-0.3.0/lib/gmail.rb:23:in `initialize'
        from send5.rb:6:in `new'
        from send5.rb:6:in `<main>'

メッセージにあるように、アプリケーション固有のパスワードを設定する必要がある。

アプリケーション固有のパスワードを使用してログインする - Google アカウント ヘルプ

手順どおりに作業し、パスワードを取得する。

from も要るらしいので追加。

結局こうなった。

# coding: utf-8

require 'gmail'

Gmail.new('ユーザー名', 'アプリケーション固有のパスワード') do |gmail|
  email = gmail.generate_message do
    from "miwarin@gmail.com"
    to "miwarin@example.gr.jp"
    subject "test1"
    body "test1"
  end
  email.deliver!
end

実行すると SMTP の実況ログが印字される。

% ruby send5.rb
-> "220 mx.google.com ESMTP xxxxxxxxxxxxxxx - gsmtp\r\n"
<- "EHLO miwarin\r\n"
-> "250-mx.google.com at your service, [xxx.xxx.xxx.xxx]\r\n"
-> "250-SIZE 35882577\r\n"
-> "250-8BITMIME\r\n"
-> "250-STARTTLS\r\n"
-> "250 ENHANCEDSTATUSCODES\r\n"
<- "STARTTLS\r\n"
-> "220 2.0.0 Ready to start TLS\r\n"
<- "EHLO miwarin\r\n"
-> "250-mx.google.com at your service, [xxx.xxx.xxx.xxx]\r\n"
-> "250-SIZE 35882577\r\n"
-> "250-8BITMIME\r\n"
-> "250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN\r\n"
-> "250 ENHANCEDSTATUSCODES\r\n"
<- "AUTH PLAIN xxxxxxxxxxxxxxxxxxxxx\r\n"
-> "235 2.7.0 Accepted\r\n"
<- "MAIL FROM:<miwarin@gmail.com>\r\n"
-> "250 2.1.0 OK xxxxxxxxxxxxxxxxxxxxx - gsmtp\r\n"
<- "RCPT TO:<miwarin@example.gr.jp>\r\n"
-> "250 2.1.5 OK xxxxxxxxxxxxxxxxxxxxx - gsmtp\r\n"
<- "DATA\r\n"
-> "354  Go ahead xxxxxxxxxxxxxxxxxxxxx - gsmtp\r\n"
writing message from String
wrote 269 bytes
-> "250 2.0.0 OK 1377045178 xxxxxxxxxxxxxxxxxxxxx - gsmtp\r\n"
<- "QUIT\r\n"
-> "221 2.0.0 closing connection xxxxxxxxxxxxxxxxxxxxx - gsmtp\r\n"

日本語

charset=iso-2022-jp 且つ Content-Transfer-Encoding: 7bit に設定したいのだが、ruby-gmail でどうすりゃいいのか分からない( ruby-gmail/lib/gmail.rb から mail/lib/mail/message.rb が呼ばれる )

これだとエラーになる。

  email = gmail.generate_message do
     :
    subject "ほげ"
    body "ほげほげ"
    charset = 'iso-2022-jp'
    add_content_transfer_encoding;
  end

mikel/mail の場合はこうすればいいのだがー

mail = Mail.new
mail.from = 'miwarin@gmail.com'
mail.to =  'miwarin@example.gr.jp'
mail.subject = '日本語タイトル' 
mail.charset ='iso-2022-jp'
mail.add_content_transfer_encoding
mail.body  = '日本語本文'
mail.deliver

_ 仕事場打ち上げ

熔岩石焼 酉鳥

6 月からの業務についてようやく一区切り付いたので打ち上げ。

IMG_0001.JPG

IMG_0003.JPG

IMG_0006.JPG

IMG_0007.JPG

IMG_0008.JPG

_ [那珂][艦これ]艦これ

那珂ちゃんだよー