Created
June 11, 2012 22:20
-
-
Save katahirado/2913098 to your computer and use it in GitHub Desktop.
オープンアワーの告知をTDCと自分のブログに送るスクリプト SMTP over SSLかつ、オレオレ証明書を使っているSMTPサーバで送信する場合(認証方式PLAIN)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "mail" | |
gem "mail-iso-2022-jp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require "date" | |
require "mail" | |
require "mail-iso-2022-jp" | |
USAGE = <<USG | |
Usage: open_hour_mail 6/8 | |
Date format pattern mm/dd | |
USG | |
REPLACE = "@@DATE@@" | |
SMTP_SERVER = "smtp.example.com" | |
SMTP_PORT = 465 | |
HATENA_ADDRESS="メール投稿用はてなアドレス" | |
TDC_ADDRESS="TDCのMLアドレス" | |
FROM_ADDRESS="自分のメールアドレス" | |
ACCOUNT="メールのアカウント名" | |
PASSWORD="メールのパスワード" | |
TAG="[TDC]" | |
TITLE="オープンアワー@片平堂" | |
TITLE_END_HATENA="告知" | |
TITLE_END_TDC="のご案内" | |
MESSAGE ="皆さんこんにちは。片平です。\n" | |
SIGNATURE= <<EOF | |
-- | |
片平堂 | |
片平裕市 | |
宮城県仙台市青葉区本町1丁目12-2モンテベルデ花京院506号 | |
片平のメールアドレス | |
EOF | |
def print_usage_and_exit | |
print USAGE | |
exit | |
end | |
#認証方式PLAIN,オレオレ証明書、SMTP over SSLの場合 | |
def smtp_default_set | |
#送信設定をセット | |
Mail.defaults do | |
delivery_method :smtp, { | |
:address => SMTP_SERVER, | |
:port => SMTP_PORT, | |
:domain => "localhost.localdomain", | |
:user_name => ACCOUNT, | |
:password => PASSWORD, | |
:authentication => "plain", | |
:openssl_verify_mode => "none", | |
:ssl => true | |
} | |
end | |
end | |
def send_mail(to_address, mail_subject, mail_body) | |
Mail.new(:charset => 'ISO-2022-JP') do | |
from FROM_ADDRESS | |
to to_address | |
subject mail_subject | |
body mail_body | |
end.deliver | |
end | |
def hatena_title(date_s) | |
TAG+date_s+TITLE+TITLE_END_HATENA | |
end | |
def tdc_title(date_s) | |
date_s+TITLE+TITLE_END_TDC | |
end | |
def tdc_body(content) | |
MESSAGE+content+SIGNATURE | |
end | |
#PATHの通った所に、このファイルだけシンボリックリンクを作成して置いているため | |
def dirname | |
if File.symlink?(__FILE__) | |
File.dirname(File.readlink(__FILE__)) | |
else | |
File.dirname(__FILE__) | |
end | |
end | |
def filename(d) | |
if d.tuesday? | |
"tuesday.txt" | |
elsif d.wednesday? | |
"wednesday.txt" | |
else | |
"tuesday.txt" | |
end | |
end | |
print_usage_and_exit if ARGV.size==0 | |
#引数読み込み | |
date_s= ARGV.shift | |
begin | |
date = Date.strptime(date_s, "%m/%d") | |
rescue ArgumentError | |
print_usage_and_exit | |
end | |
smtp_default_set() | |
s = File.read(dirname+'/'+filename(date), :encoding => Encoding::UTF_8) | |
content = s.gsub!(REPLACE, date_s) | |
#はてなに送信(火曜日,水曜日) | |
send_mail(HATENA_ADDRESS, hatena_title(date_s), content) if date.tuesday? or date.wednesday? | |
#TDCに送信(火曜日) | |
send_mail(TDC_ADDRESS, tdc_title(date_s), tdc_body(content)) if date.tuesday? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@DATE@@にオープンアワーを片平堂オフィスで行います。 | |
詳細は以下をご覧ください。お気軽にどうぞ。 | |
----------------------------------------------------------------------- | |
オープンアワー@片平堂 | |
----------------------------------------------------------------------- | |
・日時 | |
@@DATE@@(火) 7:00〜12:00 | |
出入りは自由にどうぞ、参加、退出の時間もご自由に | |
・場所 | |
片平堂 http://katahirado.jp/about.html | |
http://maps.google.co.jp/maps?q=%E4%BB%99%E5%8F%B0%E5%B8%82%E9%9D%92%E8%91%89%E5%8C%BA%E6%9C%AC%E7%94%BA1-12-2&hl=ja&ie=UTF8&ll=38.266118,140.879188&spn=0.009822,0.019076&hnear=%E5%AE%AE%E5%9F%8E%E7%9C%8C%E4%BB%99%E5%8F%B0%E5%B8%82%E9%9D%92%E8%91%89%E5%8C%BA%E6%9C%AC%E7%94%BA%EF%BC%91%E4%B8%81%E7%9B%AE%EF%BC%91%EF%BC%92%E2%88%92%EF%BC%92&gl=jp&t=m&z=16&brcurrent=3,0x5f8a2826f0704f57:0x1a70d9b7c411e4c2,0,0x5f8a2826f7863c8b:0xb250301829f18379&layer=c&cbll=38.266095,140.879316&panoid=J1zVp0HV6Q8VdhAdZGdgiA&cbp=12,0,,0,0 | |
入り口は、歯科がある2階にあがる階段と利休が入っているビルの間です。 | |
奥にエレベーターがあります。 | |
・費用 | |
100円/学生の方無料(主に飲み物代、学生の方は学生と分かるものをお持ちください。片平と面識のある方は不要です) | |
・内容 | |
読書、プログラミングなど各自やりたいことを行う活動です。 | |
・参加方法 | |
ふらっときていただいて構いません。連絡不要です。 | |
連絡しないと気が済まないという方は、メールなりTwitterなりFacebookなりで連絡ください。 | |
・必要な物 | |
ノートPC、書籍など各自必要だと思うものをご持参ください。 | |
・ネットワーク | |
イーモバイルのLTE回線があります | |
・電源 | |
使用可能です。 | |
・その他 | |
備え付けの飲み物、食べ物は好きなだけどうぞ。 | |
おいてある書籍も自由にお使いください。 | |
http://f.hatena.ne.jp/yuichi_katahira/20110710145316 | |
http://f.hatena.ne.jp/yuichi_katahira/20110710145314 | |
備え付けのハンガーもご自由にどうぞ。 | |
http://f.hatena.ne.jp/yuichi_katahira/20120508065750 | |
飲食持ち込みもOKです。朝食なう、おやつなうも問題ありません。 | |
----------------------------------------------------------------------- | |
宜しくお願いします:-) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@DATE@@にオープンアワーを片平堂オフィスで行います。 | |
ラビックスさんの朝活が行われる場合、9時ぐらいから12時までです。 | |
ラビックスさんの朝活が行われなかった場合、8時から12時までとなります。 | |
ラビックスさんの朝活が行われるかどうかは、xibbarさんのブログを確認ください。 | |
内容、参加方法等については片平堂で毎週火曜日に行っているオープンアワーと同様です。 | |
宜しくお願いいたします :-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment