• 大小: 5KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: Python
  • 标签: python  

资源简介

python GUI实现简易发送邮件程序。

资源截图

代码片段和文件信息

#!/usr/bin/env python
#coding=utf-8


from smtplib import *
from Tkinter import *
import tkMessageBox
import string


class loginPage(object):


    def __init__(self master info=‘Mail Send System‘):
        self.master = master
        self.mainlabel = Label(master text=info justify=CENTER)
        self.mainlabel.grid(row=0 columnspan=3)


        self.user = Label(master text=‘username‘ borderwidth=2)
        self.user.grid(row=1 sticky=W)


        self.pwd = Label(master text=‘password‘ borderwidth=2)
        self.pwd.grid(row=2 sticky=W)


        self.userEntry = Entry(master)
        self.userEntry.grid(row=1 column=1 columnspan=2)
        self.userEntry.focus_set()


        self.pwdEntry = Entry(master show=‘*‘)
        self.pwdEntry.grid(row=2 column=1 columnspan=2)


        self.loginButton = Button(master text=‘Login‘ borderwidth=2 command=self.login)
        self.loginButton.grid(row=3 column=1)


        self.clearButton = Button(master text=‘Clear‘ borderwidth=2 command=self.clear)
        self.clearButton.grid(row=3 column=2)


    def login(self):
        self.username = self.userEntry.get().strip()
        self.passwd = self.pwdEntry.get().strip()
        if len(self.username) == 0 or len(self.passwd) == 0 or ‘@‘ not in self.username:
            tkMessageBox.showwarning(‘警告‘ ‘用户名或者密码为空或邮件格式不正确‘)


            self.clear()
            self.userEntry.focus_set()
            return


        self.getSmtpHost()
        self.connect()


    def connect(self):
        ‘this method will try to connet the SMTP server according the current user‘
        HOST = ‘smtp.‘ + self.smtp +‘.com‘
        try:
            self.mySMTP = SMTP(HOST)
            self.mySMTP.login(self.username self.passwd)
        #except SMTPConnectError:
        except Exception e:
            tkMessageBox.showerror(‘连接错误‘ ‘%s‘ % e)
            return
        self.mySendMail = sendMail(self.master self.mySMTP self.username)


    def clear(self):
        self.userEntry.delete(0 END)
        self.pwdEntry.delete(0 END)


    def getSmtpHost(self):
        ‘this method try to obtian the SMTP HOST according the user account‘
        firstSplit = self.username

评论

共有 条评论