1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!/usr/bin/env python
#pyMail 0.1
#my first program with python and anygui interface
#coded by teknux ~ teknux@ustc.edu
#2002/11/4
#copyright 2002 under GPL
from anygui import *
import smtplib
from email.MIMEText import MIMEText
import sys as sys
#edit these fields with your informations
mail_sender = "teknux@localhost"
mail_from = "teknux@localhost"
#initialize window
app = Application()
win = Window(title="pyMail 0.1",size=(460,385))
app.add(win)
opt = Options(left=5, width=21, height=30)
banner = Label(size=(70,25), position=(385,10), text="pyMail 0.1")
to = Label(opt, text="To:")
to_text = TextField(size=(230,25))
win.add((to,to_text), position=(0,10), direction="right", space=5)
win.add(banner) subject = Label(size=(51,25), text="Subject:")
subject_text = TextField(size=(398,25))
win.add((subject,subject_text), position=(0,45), direction="right", space=5)
body = TextArea(size=(450,250))
win.add(body, position=(5,80))
btn_send = Button(left=5, size=(100,30), text="Send message")
btn_exit = Button(left=5, size=(100,30), text="Exit")
status = Label(size=(240,25), text="...status...")
win.add((btn_send,btn_exit,status), position=(5,350), space=6)
def statbar(stat_msg):
status.text = stat_msg status.refresh()
def sendmail(**args):
msg = MIMEText(body.text)
msg["Subject"] = subject_text.text
msg["From"] = mail_from
msg["To"] = to_text.text
mail_to = to_text.text
mail = smtplib.SMTP()
statbar("connecting to SMTP")
mail.connect()
statbar("sendin message")
mail.sendmail(mail_sender, mail_to, msg.as_string())
statbar("done")
mail.close()
def exit(**args):
sys.exit(2)
link(btn_exit, exit)
link(btn_send, sendmail)
app.run()
|