I tested to send mail from gmail by python. It will send to mail what Livedoor Weather Web Service information. I tried to get weather informations of kyoto city. If you want to change city,please change city number and day parameter.
# -*- coding: utf-8 -*- import urllib2 import sys import xml.dom.minidom from email.MIMEText import MIMEText from email.Header import Header from email.Utils import formatdate import smtplib class Load(object): def __init__(self,spot=None): self.url = "http://weather.livedoor.com/forecast/webservice/rest/v1?city=%s&day=%s" if spot != None: (self.spot,self.day) = spot.values() self.url = self.url % (self.spot,self.day) else: sys.exit() print "Spot is:",self.url def pasu(self,nodelist): ret = [] node_obj = nodelist.childNodes for i in node_obj: return i.data def u_read(self): area_list= [] opener = urllib2.urlopen(self.url).read() tree = xml.dom.minidom.parseString(opener) title = tree.getElementsByTagName("title")[:3] celsius = tree.getElementsByTagName("celsius") for i in title: area_list.append(self.pasu(i)) for j in celsius: area_list.append(self.pasu(j)) weather_data = "\n".join(area_list).encode("ISO-2022-JP") return weather_data class Send_mail(object): def __init__(self,subj,from_add,to_add,password): self.subj = subj self.from_add = from_add self.to_add = to_add self.password = password def build(self,mess_body): msg_obj = MIMEText(mess_body,"plain","ISO-2022-JP") msg_obj["Subject"] = Header(self.subj,"ISO-2022-JP") msg_obj["From"] = self.from_add msg_obj["To"] = self.to_add msg_obj["Date"] = formatdate() return msg_obj def login(self,opa): send_obj = smtplib.SMTP("smtp.gmail.com", 587) send_obj.starttls() send_obj.login(self.from_add,self.password) send_obj.sendmail(self.from_add,self.to_add,opa.as_string()) send_obj.quit() if __name__ == '__main__': x = Load({"city":"79","day":"tomorrow"}) send_msg = x.u_read() title = u"天気のメール送ります" from_add = "your mail address" to_add = "send to address" password = "gmail password" mail = Send_mail(title,from_add,to_add,password) send = mail.build(send_msg) mail.login(send)
It referred.
Pythonでメールを送信する
http://labs.unoh.net/2007/06/python_2.html
お天気Webサービス仕様
http://weather.livedoor.com/weather_hacks/webservice.html