Python篇-简易邮箱

python编写简易邮箱
打开邮箱的IMAP/SMTP服务
1、进入qq邮箱账户设置页面

%title插图%num

2、找到服务,打开服务

%title插图%num

3、复制下授权码(编程时需要)

%title插图%num
代码实现
”’
发送邮件
”’
import tkinter
import smtplib
from email.mime.text import MIMEText

class SendMail:
# 初始化画窗口
def __init__(self):
# 创建窗口对象
windows = tkinter.Tk()
# 设置标题
windows.title(“邮件发送”)
# 设置大小
windows.geometry(“500×300″)
# 设置窗口大小不可变
windows.resizable(width=False, height=False)

# 创建文本标签
text_title = tkinter.Label(windows, text=”\n\n邮件主题”)
# 展示文本标签
text_title.pack()
self.ed_sendTitle = tkinter.Entry(windows, width=”50″)
self.ed_sendTitle.pack();

text_msg = tkinter.Label(windows, text=”邮件正文”)
text_msg.pack()
self.ed_sendMsg = tkinter.Entry(windows, width=”50″)
self.ed_sendMsg.pack();

text_sendName = tkinter.Label(windows, text=”发件人昵称”)
text_sendName.pack()
self.ed_sendName = tkinter.Entry(windows, width=”50″)
self.ed_sendName.pack();

text_toUserName = tkinter.Label(windows, text=”收件人邮箱”)
text_toUserName.pack()
self.ed_toUserName = tkinter.Entry(windows, width=”50″)
self.ed_toUserName.pack();

btn = tkinter.Button(windows, text=”发送”, command=self.sendMsg)
btn.pack()

# 显示窗口
windows.mainloop()

def sendMsg(self):
#发送邮件
#标题
title = self.ed_sendTitle.get()
# 正文
text = self.ed_sendMsg.get()
# 发件人
sendName = self.ed_sendName.get()
sendUserName = “[email protected]
sendCode = “usdtkujdfdfeehdc”
#[email protected]
# 收件人邮箱
toUserName = self.ed_toUserName.get()
”’
1、封装邮件
”’
msg = MIMEText(text)
msg[“subject”] = title
msg[“from”] = sendName
”’
2、登录邮箱
”’
email = smtplib.SMTP(“smtp.qq.com”, 25)
email.login(sendUserName, sendCode)
”’
3、发送邮件
”’
email.sendmail(sendUserName, toUserName, msg=msg.as_string())
”’
4、退出邮箱
”’
email.quit()

if __name__ == ‘__main__’:
sendMail = SendMail()

运行效果

%title插图%num