PR
Calendar
Keyword Search
Category
Free Space
# -*- coding: utf-8 -*-
import smtplib
from_address = 'your_email_address@gmail.com'
to_address = 'to_mail_address@gmail.com'
message = 'Message to send.'
# Gmail のユーザー名とパスワード
username = 'your_username'
password = 'your_password'
# メールを送信する
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.ehlo()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
headers = dict()
headers["Subject"] = "これはテストですよ"
headers["To"] = ["to_address1@example.com", "to_address2@example.com"]
headers["From"] = "Your Name <your_address@gmail.com>"
password = "your_password"
body = u"""今日の天気は雨でした。
--
民主党は滅びよ!
"""
email_it_via_gmail(headers, text=body, password=password)
import imaplib
from email.header import decode_header
gmail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
gmail.login('your_address', 'your_password')
# 受信トレイを選択
gmail.select('INBOX')
# 未読のカウント
status, response = gmail.status('INBOX', "(UNSEEN)")
unreadcount = int(response[0].split()[2].strip(').,]'))
print unreadcount
# 受信トレイから、1つめのメールを取り出してみる。
status, count = gmail.select('Inbox')
status, count = gmail.select()
status, data = gmail.fetch(count[0], '(UID BODY[TEXT])')
print data[0][1]
# デコードしないとだめだね
# サブジェクトを表示してみる
_,[data] = gmail.search(None,'ALL')
for i in data.split(' '):
_,sub = gmail.fetch(i,'(BODY[HEADER.FIELDS (SUBJECT)])')
# デコードして表示してみようか
decoded = decode_header(sub[0][1].strip())[1]
print unicode(decoded[0], decoded[1])
gmail.close()
gmail.logout()
janome を使った Python プログラムを pyi… 2024.04.08
Tkinter でも、見た目のよい GUI を作れる 2024.02.25
Chromecast を Python で制御する 2016.01.10