

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>“南船北馬” &#187; Gmail</title>
	<atom:link href="http://aoshiman.net/weblog/category/gmail/feed/" rel="self" type="application/rss+xml" />
	<link>http://aoshiman.net/weblog</link>
	<description>不定期更新且つ、最新情報に対して常に周回遅れ気味に追っかけているブログです</description>
	<lastBuildDate>Tue, 20 Oct 2009 11:07:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[Python]Twitter版LogWatchのようなもの</title>
		<link>http://aoshiman.net/weblog/2009/05/05/twitter_logwatch/</link>
		<comments>http://aoshiman.net/weblog/2009/05/05/twitter_logwatch/#comments</comments>
		<pubDate>Tue, 05 May 2009 10:53:01 +0000</pubDate>
		<dc:creator>aoshiman</dc:creator>
				<category><![CDATA[Gmail]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[smtplib]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://aoshiman.net/weblog/?p=312</guid>
		<description><![CDATA[				GW期間に３連休（年に２回あるかどうか！というくらい貴重）をもらったので、Pythonのお勉強を兼ねてTwitter版LogWatchのようなものを作ってみました。
				
				
				24時過ぎとかにcronで実行させると、FriendsとFollowersそれぞれのリストを前日に保存しておいたリストと照合し、追加した（された）および削除した（された）Friends/FollowersをリストアップしてGmailで自分宛に送信します。Twitter APIを扱うモジュールはPython-twitterというものを使用していますが、前回と同じく、easy_installで入るものでなくtrunkにあるものを使用しています。
				作ってみて色々思ったこと
				
				結構行数が増えてきたので、Classにまとめようと思ったけど、次回チャレンジする
				Pythonで書いている人は文字列囲むのにダブルクォーテーションとシングルクォーテーションどちらなのか。もしくは使い分けしているのか
				変数命名が納得いかない。どうしたものか。
				自分で書いた英語がそもそも怪しい＞＜
				コードを書き始めてから、このblogを書き始めるまで１３時間くらいかかった。半年前だったら１週間以上かかっただろう。この進歩（牛歩だが）が嬉しい
				
				コードはこちら。Python2.6（MacOSX dmg）で動作確認は取れています。但しcronでの運用はまだ行っていません（先日セッティングした自鯖に入れるつもり）。
				
#!/usr/bin/env python
# coding: utf-8
#
# Please Note it.
# Python-twitter od the trunk version(r137 or higher)in necessary.
# svn checkout http://python-twitter.googlecode.com/svn/trunk/ python-twitter
#

import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate
import twitter
from datetime import *

TWITTER_USER = &#34;TWITTER_USER&#34;
TWITTER_PASSWD = &#34;TWITTER_PASSWARD&#34;
GMAIL_USER = &#34;GMAIL_ACCOUNT&#34;
GMAIL_PASSWD = &#34;GMAIL_PASSWARD&#34;
api = twitter.Api(TWITTER_USER, TWITTER_PASSWD)
FRIENDS_LIST = &#34;friends.txt&#34;
FOLLOWERS_LIST = &#34;followers.txt&#34;

def get_allfriends(): #friendを取得
    [...]]]></description>
			<content:encoded><![CDATA[				<p>GW期間に３連休（年に２回あるかどうか！というくらい貴重）をもらったので、Pythonのお勉強を兼ねてTwitter版<a href="http://www.atmarkit.co.jp/flinux/rensai/root04/root04c.html"></a>LogWatchのようなものを作ってみました。</p>
				<p><a class="" rel="" title="20090505_02" href="http://www.flickr.com/photos/aoshiman/3503817600/"><img src="http://static.flickr.com/3374/3503817600_a2f23125e6.jpg" alt="20090505_02"></a></p>
				<p><span id="more-312"></span><br />
				24時過ぎとかにcronで実行させると、FriendsとFollowersそれぞれのリストを前日に保存しておいたリストと照合し、追加した（された）および削除した（された）Friends/FollowersをリストアップしてGmailで自分宛に送信します。Twitter APIを扱うモジュールはPython-twitterというものを使用していますが、<a href="http://aoshiman.net/weblog/2009/04/17/python-twitter-in-3d-on-ubigraph/">前回</a>と同じく、easy_installで入るものでなくtrunkにあるものを使用しています。</p>
				<h3>作ってみて色々思ったこと</h3>
				<ul>
				<li>結構行数が増えてきたので、Classにまとめようと思ったけど、次回チャレンジする</li>
				<li>Pythonで書いている人は文字列囲むのにダブルクォーテーションとシングルクォーテーションどちらなのか。もしくは使い分けしているのか</li>
				<li>変数命名が納得いかない。どうしたものか。</li>
				<li>自分で書いた英語がそもそも怪しい＞＜</li>
				<li>コードを書き始めてから、このblogを書き始めるまで１３時間くらいかかった。半年前だったら１週間以上かかっただろう。この進歩（牛歩だが）が嬉しい</li>
				</ul>
				<p>コードはこちら。Python2.6（MacOSX dmg）で動作確認は取れています。但しcronでの運用はまだ行っていません（先日セッティングした自鯖に入れるつもり）。</p>
				<pre class="brush: python;">
#!/usr/bin/env python
# coding: utf-8
#
# Please Note it.
# Python-twitter od the trunk version(r137 or higher)in necessary.
# svn checkout http://python-twitter.googlecode.com/svn/trunk/ python-twitter
#

import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate
import twitter
from datetime import *

TWITTER_USER = &quot;TWITTER_USER&quot;
TWITTER_PASSWD = &quot;TWITTER_PASSWARD&quot;
GMAIL_USER = &quot;GMAIL_ACCOUNT&quot;
GMAIL_PASSWD = &quot;GMAIL_PASSWARD&quot;
api = twitter.Api(TWITTER_USER, TWITTER_PASSWD)
FRIENDS_LIST = &quot;friends.txt&quot;
FOLLOWERS_LIST = &quot;followers.txt&quot;

def get_allfriends(): #friendを取得
    friends, cnt = [], 1
    while not len(friends) % 100:
        friends += api.GetFriends(page=cnt)
        cnt += 1
    friend = []
    for i in friends:
        user = i.screen_name
        user = user + &quot;\n&quot;
        friend.append(user)
    return friend

def get_allfollowers(): #followerを取得
    followers, cnt = [], 1
    while not len(followers) % 100:
        followers += api.GetFollowers(page=cnt)
        cnt += 1
    follower = []
    for i in followers:
        user = i.screen_name
        user = user + &quot;\n&quot;
        follower.append(user)
    return follower

def flw_list_open(FOLLOWERS_LIST): #前回のfollowerリスト読込
    flw = open(FOLLOWERS_LIST, &quot;r&quot;)
    flw_list = flw.readlines()
    flw.close()
    return flw_list

def frd_list_open(FRIENDS_LIST): #前回のfriendリスト読込
    frd = open(FRIENDS_LIST, &quot;r&quot;)
    frd_list = frd.readlines()
    frd.close()
    return frd_list

def set_followers(): #followerリストのマッチング
    FLW, RMV = &quot;%(flws)s&quot;, &quot;%(rmv)s&quot;
    follower = get_allfollowers()
    flw_list = flw_list_open(FOLLOWERS_LIST)
    fl = open(FOLLOWERS_LIST, &quot;w&quot;)
    new_flw = []
    for flws in follower:
        if flws not in flw_list:
            new_flw.append(FLW % locals())
        fl.write(flws)

    rm_flw = []
    for rmv in flw_list:
        if rmv not in follower:
            rm_flw.append(RMV % locals())
    return new_flw, rm_flw, follower

def set_friends(): #friendリストのマッチング
    FRD, RMV = &quot;%(frds)s&quot;, &quot;%(rmv)s&quot;
    friend = get_allfriends()
    frd_list = frd_list_open(FRIENDS_LIST)
    fl = open(FRIENDS_LIST, &quot;w&quot;)
    new_frd = []
    for frds in friend:
        if frds not in frd_list:
            new_frd.append(FRD % locals())
        fl.write(frds)

    rm_frd = []
    for rmv in frd_list:
        if rmv not in friend:
            rm_frd.append(RMV % locals())
    return new_frd, rm_frd, friend

def create_message(from_addr, to_addr, subject, body, encoding):
    msg = MIMEText(body.encode(encoding), &quot;plain&quot;, encoding)
    msg[&quot;Subject&quot;] = Header(subject, encoding)
    msg[&quot;From&quot;] = from_addr
    msg = MIMEText(body.encode(encoding), &quot;plain&quot;, encoding)
    msg[&quot;Subject&quot;] = Header(subject, encoding)
    msg[&quot;From&quot;] = from_addr
    msg[&quot;To&quot;] = to_addr
    msg[&quot;Date&quot;] = formatdate()
    return msg

def send_via_gmail(from_addr, to_addr, msg):
    s = smtplib.SMTP(&quot;smtp.gmail.com&quot;, 587)
    s.ehlo()
    s.starttls()
    s.ehlo()
    s.login(GMAIL_USER, GMAIL_PASSWD)
    s.sendmail(from_addr, to_addr, msg.as_string())
    s.close()

def main():
    DATETIME = datetime.now()
    YESTERDAY = DATETIME + timedelta(hours=-24)
    DATESTR = DATETIME.strftime(&quot;%Y/%m/%d% %H:%M:%S&quot;)
    STR_YESTERDAY = YESTERDAY.strftime(&quot;%Y/%m/%d&quot;)

    subject = &quot;Logwatch for %s's Twitter&quot; % TWITTER_USER
    from_addr = GMAIL_USER
    to_addr = GMAIL_USER
    new_flw, rm_flw, follower = set_followers()
    new_frd, rm_frd, friend = set_friends()

    &quot;&quot;&quot;
    メールの本文にあたるところ
    もうちょっとうまく書けないものか
    あとそもそも英語があやしい
    &quot;&quot;&quot;
    body = &quot;################ Logwatch for %s's Twitter ################&quot; % TWITTER_USER + &quot;\n&quot;
    body += &quot;Processing Initiated:%s&quot; % DATESTR + &quot;\n&quot;
    body += &quot;Date Range Processed:%s&quot; % STR_YESTERDAY + &quot;\n&quot;
    body += &quot;Period is day.&quot; + &quot;\n&quot;
    body += &quot;\n&quot;
    body += &quot;--------------------- Followers Begin ---------------------&quot; + &quot;\n&quot;
    body += &quot;%s Users Followers&quot; % len(follower) + &quot;\n&quot;
    body += &quot;Followed by ...&quot; + &quot;\n&quot;
    if new_flw == []:
        body += &quot;Nobody followed you yesterday.&quot; + &quot;\n&quot;
    else:
        for nfl in new_flw:
            body += &quot;%s is followed you yesterday&quot; % nfl + &quot;\n&quot;
    body += &quot;Rmoved by ...&quot; + &quot;\n&quot;
    if rm_flw == []:
        body += &quot;Nobody Removed you yesterday.&quot; + &quot;\n&quot;
    else:
        for rfl in rm_flw:
            body += &quot;%s is Removed you yesterday&quot; % rfl + &quot;\n&quot;
    body += &quot;---------------------- Followers End ---------------------&quot; + &quot;\n&quot;
    body += &quot;\n&quot;
    body += &quot;--------------------- Friends Begin ---------------------&quot; + &quot;\n&quot;
    body += &quot;%s Users Friends&quot; % len(friend) + &quot;\n&quot;
    body += &quot;Following ...&quot; + &quot;\n&quot;
    if new_frd == []:
        body += &quot;No follow yesterday&quot; + &quot;\n&quot;
    else:
        for nfr in new_frd:
            body += &quot;following %s yesterday&quot; % nfr + &quot;\n&quot;
    body += &quot;Rmoving ...&quot; + &quot;\n&quot;
    if rm_frd == []:
        body += &quot;No Remove yesterday.&quot; + &quot;\n&quot;
    else:
        for rfr in rm_frd:
            body += &quot;Removing %s yesterday&quot; % rfr + &quot;\n&quot;
    body += &quot;---------------------- Friends End ---------------------&quot; + &quot;\n&quot;
    body += &quot;\n&quot;
    body += &quot;############## Logwatch for %s's Twitter End ##############&quot; % TWITTER_USER + &quot;\n&quot;
    msg = create_message(from_addr, to_addr, subject, body, &quot;utf-8&quot;)
    send_via_gmail(from_addr, to_addr, msg)

if __name__ == &quot;__main__&quot;:
    main()
</pre>
				<p>[2009年5月6日追記]<br />
				送られてきたメールを確認すると、改行されたくないところで改行されてたりするので、時間見つけて修正します。<br />
				[追記ここまで]</p>
				<p>[2009年6月20日追記]<br />
				最近Follower数がかなり少なくカウントされていると思っていて、時間がとれたので調べてみたんだけど、page=1が97になっていてカウントが止まってしまっている。100で割り切れなくなるまでカウントされるロジックなので、本当に97ならしかたがないのだけど、page=2にもFollowerがちゃんとある。調べた結果がこちら。うーん変だなあ・・</p>
				<pre class="brush: python;">
[root@centos ~]# python
Python 2.6.2 (r262:71600, May 14 2009, 20:12:16)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import twitter
&gt;&gt;&gt; api = twitter.Api('ACCOUNT', 'PASSWORD')
&gt;&gt;&gt; f = api.GetFollowers(page=2)
&gt;&gt;&gt; print len(f)
58
&gt;&gt;&gt; f = api.GetFollowers(page=1)
&gt;&gt;&gt; print len(f)
97
&gt;&gt;&gt; f = api.GetFollowers(page=3)
&gt;&gt;&gt; print len(f)
0
&gt;&gt;&gt;
</pre>
				<p>[追記ここまで]</p>
]]></content:encoded>
			<wfw:commentRss>http://aoshiman.net/weblog/2009/05/05/twitter_logwatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pythonで１日のGoogle検索履歴の一覧を作成してGmailから送信する</title>
		<link>http://aoshiman.net/weblog/2008/09/30/google_search_history/</link>
		<comments>http://aoshiman.net/weblog/2008/09/30/google_search_history/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 14:21:56 +0000</pubDate>
		<dc:creator>aoshiman</dc:creator>
				<category><![CDATA[Gmail]]></category>
		<category><![CDATA[feedparser]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[smtplib]]></category>
		<category><![CDATA[urllib]]></category>
		<category><![CDATA[RSS]]></category>

		<guid isPermaLink="false">http://aoshiman.net/weblog/?p=17</guid>
		<description><![CDATA[				今の私にとって（他の人もそうだと思いますが）、仕事プライベートに関係なく、Google検索は無くてはならないものですが、はたして１日にどのくらい検索しているのか知りたくて、リストを作成してみました。併せて前回のYahoo!天気情報のRSSと同様にGmailで送信しています。役に立つか分かりませんが、作成したコードを掲載します（スクリプトは何度も実行して成功しているものですが、実施は自己責任でお願いします）。尚、Google検索の履歴（Google Search History）はGoogleアカウントでログインしている状態で有効になります。
				作成した時のポイントとしては
				
				Google Search History は RSS で取得出来るので、feedparserを利用した
				RSS は Basic認証がかかる為、urllibのFancyURLopenerを使用した
				RSSのURLは件数のパラメータ（&#038;num=）が無い場合、25件しか取得出来ないようなので（自分調べ）、１日で必要な件数を設定した
				取得出来る日時がGMTなので、日本時間（＋9h）にする方法に悩んだ
				
				
# coding:utf-8

import urllib
import feedparser
import email.Utils
from time import *

import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate

class MyURLopener(urllib.FancyURLopener):
    def prompt_user_passwd(self, host, realm):
        return ('YOUR_GMAIL_ADDRESS', 'YOUR_PASSWORD')

def feed_parse(u):
    f = opener.open(u)
    [...]]]></description>
			<content:encoded><![CDATA[				<p>今の私にとって（他の人もそうだと思いますが）、仕事プライベートに関係なく、Google検索は無くてはならないものですが、はたして１日にどのくらい検索しているのか知りたくて、リストを作成してみました。併せて前回の<a href="http://aoshiman.net/weblog/2008/09/21/yahoo_rss_gmail/">Yahoo!天気情報のRSS</a>と同様にGmailで送信しています。役に立つか分かりませんが、作成したコードを掲載します（スクリプトは何度も実行して成功しているものですが、実施は自己責任でお願いします）。尚、Google検索の履歴（Google Search History）はGoogleアカウントでログインしている状態で有効になります。<br />
				作成した時のポイントとしては<span id="more-17"></span></p>
				<ul>
				<li>Google Search History は RSS で取得出来るので、feedparserを利用した</li>
				<li>RSS は Basic認証がかかる為、urllibのFancyURLopenerを使用した</li>
				<li>RSSのURLは件数のパラメータ（&#038;num=）が無い場合、25件しか取得出来ないようなので（自分調べ）、１日で必要な件数を設定した</li>
				<li>取得出来る日時がGMTなので、日本時間（＋9h）にする方法に悩んだ</li>
				</ul>
				<pre class="brush: python;">
# coding:utf-8

import urllib
import feedparser
import email.Utils
from time import *

import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate

class MyURLopener(urllib.FancyURLopener):
    def prompt_user_passwd(self, host, realm):
        return ('YOUR_GMAIL_ADDRESS', 'YOUR_PASSWORD')

def feed_parse(u):
    f = opener.open(u)
    d = feedparser.parse(f)
    TEMPLATE = '* %(entry_date)s : %(entry_title)s'
    feed = []
    for entry in d.entries:
        feed.append([entry.date, entry.title])
    feed.reverse()

    item_list = []
    today = localtime(time())[0:3]
    for i in feed:
        entry_date, entry_title = i[0], i[1]
        entry_date = localtime(mktime(email.Utils.parsedate(entry_date)) + 32400)
        if entry_date[0:3] == today:
            entry_date = strftime('%Y/%m/%d %H:%M:%S',entry_date)
            item_list.append(TEMPLATE % locals())
    items = '\n'.join(item_list)

    return items

def create_message(from_addr, to_addr, subject, body, encoding):
    msg = MIMEText(body.encode(encoding), 'plain', encoding)
    msg['Subject'] = Header(subject, encoding)
    msg['From'] = from_addr
    msg['To'] = to_addr
    msg['Date'] = formatdate()

    return msg

def send_via_gmail(from_addr, to_addr, msg):
    s = smtplib.SMTP('smtp.gmail.com', 587)
    s.ehlo()
    s.starttls()
    s.ehlo()
    s.login('YOUR_GMAIL_ADDRESS', 'YOUR_PASSWORD')
    s.sendmail(from_addr, to_addr, msg.as_string())
    s.close()

if __name__ == '__main__':
    number = '200'
    URL = 'http://www.google.com/searchhistory/?output=rss&amp;amp;amp;num=%s' % number
    opener = MyURLopener({})
    subject = 'Google search history'
    body = feed_parse(URL)
    from_addr = 'YOUR_GMAIL_ADDRESS'
    to_addr = 'xxxxxxxxxxxxx@gmail.com'
    msg = create_message(from_addr, to_addr, subject, body, 'UTF-8')
    send_via_gmail(from_addr, to_addr, msg)
</pre>
				<p>
				実際に送ってみるとこんなかんじです。これは一部分で、調べものが多いときは100件以上／日は検索していました。<br />
				<img src="http://aoshiman.net/weblog/wp-admin/user-images/20080930_01.png" alt="Gmail" /><br />
				<br />
				少しとはいえ、自分の検索を晒すのは恥ずかしい＞＜。Typoとか（笑。<br />
				これを応用すれば、twitterで検索履歴をポストすることも出来そう。とっても恥ずかしいけどね。</p>
				<h3>参考サイト</h3>
				<ul>
				<li><a href="http://d.hatena.ne.jp/mzp/20070616/twitter">みずぴー日記 今日のTwitter</a></li>
				<li><a href="http://itpro.nikkeibp.co.jp/article/COLUMN/20080407/298191/?P=2">第3回 スクレイピングにチャレンジ！</a></li>
				<li><a href="http://labs.unoh.net/2007/06/python_2.html">ウノウラボ Pythonでメールを送信したい人のためのサンプル集 </a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://aoshiman.net/weblog/2008/09/30/google_search_history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PythonでYahoo!天気情報のRSSをパースしてGmailから送信する</title>
		<link>http://aoshiman.net/weblog/2008/09/21/yahoo_rss_gmail/</link>
		<comments>http://aoshiman.net/weblog/2008/09/21/yahoo_rss_gmail/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 11:49:56 +0000</pubDate>
		<dc:creator>aoshiman</dc:creator>
				<category><![CDATA[Gmail]]></category>
		<category><![CDATA[feedparser]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[smtplib]]></category>

		<guid isPermaLink="false">http://aoshiman.net/weblog/?p=16</guid>
		<description><![CDATA[				最近、Web上の色々なコードを写経したり、変更を加えたりして少しずつPythonの勉強をしていますが、今回Setomitsさんのblogで拝見した天気予報の定期送信スクリプトを自分なりにアレンジし、Gmailから送信出来るように変更してみました。パースした内容の加工は何もしていません（したいけどまだ勉強中）。使用方法は、第１引数に送信先のメールアドレス、第２引数に地域コード（静岡県中部は5010）を与えます。書いたコードは下記の様になりました。
				
# coding: utf-8

to_addr = sys.argv[1]
area = sys.argv[2]

def create_contents(u):
    data = feedparser.parse(u)
    f = [data.feed.title] + [entry.title for entry in data.entries]
    s, b = f[0], f[1:]

    return '\n'.join(b), s

def create_message(from_addr, to_addr, subject, body, encoding):
    msg = MIMEText(body.encode(encoding), 'plain', encoding)
   [...]]]></description>
			<content:encoded><![CDATA[				<p>最近、Web上の色々なコードを写経したり、変更を加えたりして少しずつPythonの勉強をしていますが、今回Setomitsさんのblogで拝見した<a href="http://matatabi.homeip.net/blog/setomits/1335">天気予報の定期送信スクリプト</a>を自分なりにアレンジし、Gmailから送信出来るように変更してみました。パースした内容の加工は何もしていません（したいけどまだ勉強中）。使用方法は、第１引数に送信先のメールアドレス、第２引数に地域コード（静岡県中部は5010）を与えます。書いたコードは下記の様になりました。<span id="more-16"></span></p>
				<pre class="brush: python;">
# coding: utf-8

to_addr = sys.argv[1]
area = sys.argv[2]

def create_contents(u):
    data = feedparser.parse(u)
    f = [data.feed.title] + [entry.title for entry in data.entries]
    s, b = f[0], f[1:]

    return '\n'.join(b), s

def create_message(from_addr, to_addr, subject, body, encoding):
    msg = MIMEText(body.encode(encoding), 'plain', encoding)
    msg['Subject'] = Header(subject, encoding)
    msg['From'] = from_addr
    msg['To'] = to_addr
    msg['Date'] = formatdate()
    return msg

def send_via_gmail(from_addr, to_addr, msg):
    s = smtplib.SMTP('smtp.gmail.com', 587)
    s.ehlo()
    s.starttls()
    s.ehlo()
    s.login('YOUR_GMAIL_ADDRESS', 'YOUR_PASSWORD')
    s.sendmail(from_addr, to_addr, msg.as_string())
    s.close()

def main():
    from_addr = 'YOUR_GMAIL_ADDRESS'
    url = 'http://rss.weather.yahoo.co.jp/rss/days/%s.xml' % area
    body, subject = create_contents(url)
    msg = create_message(from_addr, to_addr, subject, body, 'UTF-8')
    send_via_gmail(from_addr, to_addr, msg)

if __name__ == '__main__':
    main()
</pre>
				<p><del datetime="2008-09-30T05:35:42+00:00">ここで問題（というか不思議な現象）が発生。携帯（SoftBank）やISPのアドレスに送ったメール内容はこのような感じになりますが</del><br />
				<br />
				<img src="http://aoshiman.net/weblog/wp-admin/user-images/2008092103.png" alt="webmail" /><br />
				<del datetime="2008-09-30T05:35:42+00:00">Gmailへ送った場合は途中で内容が切れてしまいます。またFromアドレスであるGmailの送信済みメール内容は、どの送信アドレスに送ったにも関わらず同じように途中で内容が切れてしまっています。</del><br />
				<br />
				<img src="http://aoshiman.net/weblog/wp-admin/user-images/2008092102.png" alt="gmail" /><br />
				<br />
				<del datetime="2008-09-30T05:35:42+00:00">とりあえずメールは携帯へ送ることになるので困りませんが、この現象については継続して調べていきます。</del><br />
				[2008年9月30日追記]<br />
				時間が掛かりましたが、コメントあったようにエンコード関係だったようで、コードの修正をしました。<br />
				[追記ここまで]</p>
				<h3>参考サイト</h3>
				<ul>
				<li><a href="http://labs.unoh.net/2007/06/python_2.html">ウノウラボ Pythonでメールを送信したい人のためのサンプル集 </a>
				</li>
				<li><a href="http://matatabi.homeip.net/blog/setomits/1335">blogSetomits 定期メール送信スクリプトのリカバリ</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://aoshiman.net/weblog/2008/09/21/yahoo_rss_gmail/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
