Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3590378
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2021-04-13 16:00:28

'''
发送邮件
'''
import tkinter
import smtplib
from email.mime.text import MIMEText


class SendMail:
# 初始化画窗口
    def __init__(self):
        # 创建窗口对象
        windows = tkinter.Tk()
        # 设置标题
        windows.title("邮件发送")
        # 设置大小
        windows.geometry("500x300")
        # 设置窗口大小不可变
        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 = "cvzhanshi@qq.com"
        sendCode = "usdtkujdfdfeehdc"
        #1091853977@qq.com
        # 收件人邮箱
        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()
————————————————

阅读(1114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~