Python篇-简易邮箱

python编写简易邮箱

打开邮箱的IMAP/SMTP服务

1、进入qq邮箱账户设置页面
在这里插入图片描述
2、找到服务,打开服务
在这里插入图片描述
3、复制下授权码(编程时需要)
在这里插入图片描述

代码实现

'''
发送邮件
'''
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()

运行效果

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猿灰灰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值