Python�Ǥ�e�᡼����������ǽ�ʤΤǤ���������Gmail��Ȥ����Ȥ�¿�����ᡢ����������Ĵ�٤Ƥߤ��Ȥ�����Gmail��ͳ�ǥ᡼���������Ǥ��뤳�Ȥ��狼��ޤ������Ĥ��Ǥˡ�PNG������ź�դˤ����������Τǡ��ޤȤ�Ƥߤޤ���
���������������Ʊ��Gmail���ɥ쥹�˻��ꤷ�Ƽ��������褦����ź�ղ����â¤ï¿½ï¿½ï¿½ï¿½È¼ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ì¤¿ï¿½ï¿½
���������ɽ����Ʊ�͡�python������ץȤ��ĥ��.py�Ȥ��ƥե��������¸���ơ����������ե�����˼¹Ը���Ϳ����ü���Ǽ¹Ԥ��뤫���ե��������֥륯��å����Ƽ¹Ԥ��ޤ���
Gmail��ͳ�ǥƥ����ȥ᡼�����������
�ޤ��������ν񼰤ǥ�����ץȤ����������ĥ��.py�Υե�����̾(�����Ǥϡ�mail-1.py�פȤ��ޤ�)���դ�����¸���ޤ����ѹ�����ɬ�פ�����Τϡ��ֻ�����ʬ�����Ǥ���
[������2010/04/22 23:35]
���֤�ȴ���Ƥ��ޤ�����[tab]����ʬ�˥��֤�ä��Ʋ�������
# -*- coding: utf-8 -*-
import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate
def create_message(from_addr, to_addr, subject, body):
[tab] msg = MIMEText(body)
[tab] msg['Subject'] = subject
[tab] msg['From'] = from_addr
[tab] msg['To'] = to_addr
[tab] msg['Date'] = formatdate()
[tab] return msg
[tab] pass
def send_via_gmail(from_addr, to_addr, msg):
[tab] s = smtplib.SMTP('smtp.gmail.com', 587)
[tab] s.ehlo()
[tab] s.starttls()
[tab] s.ehlo()
[tab] s.login('gmail�Υ��ɥ쥹', 'gmail�Υѥ����')
[tab] s.sendmail(from_addr, [to_addr], msg.as_string())
[tab] s.close()
if __name__ == '__main__':
[tab] from_addr = 'gmail�Υ��ɥ쥹'
[tab] to_addr = '������Υ��ɥ쥹'
[tab] title = '�����ȥ�'
[tab] body = '�᡼����ʸ(���Ԥ� \n ��Ȥ�)'
[tab] msg = create_message(from_addr, to_addr, title, body)
[tab] send_via_gmail(from_addr, to_addr, msg)
�����Υ��ޥ�ɤ�¹Ԥ���С�Gmail��ͳ��������Υ��ɥ쥹���˥᡼�뤬���������Ϥ��Ǥ���
$ chmod +x mail-1.py
$ ./mail-1.py
������ץȤΣ����ܤˤ��Ǥ˻��ꤷ�Ƥ��뤿�ᡢ�¹Ԥ���ݤ�python���ޥ�ɤ����פǤ���
PNG������ź�դ���Gmail��ͳ����������
Ʊ�ͤˡ������ν񼰤ǥ�����ץȤ����������ĥ��.py�Υե�����̾(�����Ǥϡ�mail-2.py�פȤ��ޤ�)���դ�����¸���ޤ����ѹ�����ɬ�פ�����Τϡ��ֻ�����ʬ�����Ǥ���
[������2010/04/22 23:50]
���֤�ȴ���Ƥ��ޤ�����[tab]����ʬ�˥��֤�ä��Ʋ�������
# -*- coding: utf-8 -*-
import smtplib
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
from email.MIMEMultipart import MIMEMultipart
from email.Header import Header
from email.Utils import formatdate
def create_message(from_addr, to_addr, subject, body, encoding):
[tab] msg = MIMEMultipart()
[tab] msg['Subject'] = Header(subject, encoding)
[tab] msg['From'] = from_addr
[tab] msg['To'] = to_addr
[tab] msg['Date'] = formatdate()
[tab] related = MIMEMultipart('related')
[tab] alt = MIMEMultipart('alternative')
[tab] related.attach(alt)
[tab] content = MIMEText(body, 'plain', encoding)
[tab] alt.attach(content)
[tab] for filename in ['png�����Υե�����̾']:
# ʣ���Υե��������ꤹ�����['�ե����룱' , '�ե����룲' , ��]�η��ˤ��롣
[tab] fp = file('%s' % filename, 'rb')
[tab] img = MIMEImage(fp.read(), 'png', name=filename)
[tab] related.attach(img)
[tab] msg.attach(related)
[tab] return msg
[tab] pass
def send_via_gmail(from_addr, to_addr, msg):
[tab] s = smtplib.SMTP('smtp.gmail.com', 587)
[tab] s.ehlo()
[tab] s.starttls()
[tab] s.ehlo()
[tab] s.login('gmail�Υ��ɥ쥹', 'gmail�Υѥ����')
[tab] s.sendmail(from_addr, [to_addr], msg.as_string())
[tab] s.close()
if __name__ == '__main__':
[tab] from_addr = 'gmail�Υ��ɥ쥹'
[tab] to_addr = '������Υ��ɥ쥹'
[tab] title = '�����ȥ�'
[tab] body = '�᡼����ʸ(���Ԥ� \n ��Ȥ�)'
[tab] msg = create_message(from_addr, to_addr, title, body, 'utf-8')
[tab] send_via_gmail(from_addr, to_addr, msg)
�����Υ��ޥ�ɤ�¹Ԥ���С�Gmail��ͳ��������Υ��ɥ쥹���˻��ꤷ��PNG������ź�դ��줿���ǥ᡼�뤬���������Ϥ��Ǥ���
$ chmod +x mail-2.py
$ ./mail-2.py
Ʊ�ͤˡ�������ץȤΣ����ܤˤ��Ǥ˻��ꤷ�Ƥ��뤿�ᡢ�¹Ԥ���ݤ�python���ޥ�ɤ����פǤ����ʤ���ź�դ�������λ����ե�����̾�����ˤ������ϡ������β����򥹥���ץȤ�Ʊ���ǥ��쥯�ȥ����¸���Ƥ���ɬ�פ�����ޤ�(�ե�ѥ��ǻ��ꤷ�����ϡ��ɤ����֤��Ƥ⹽��ʤ��Ȼפ��ޤ�����)��
[���ȵ�����]
�����Τ���ܡ�Python�ǥ᡼��������������ͤΤ���Υ���ץ뽸
[���ȵ�����]
�������ƥ�����͡�python��mail������
�ĥ�����