python3实现邮件发送可视化

本文介绍了一个使用Python编写的简单邮件发送程序。通过Tkinter创建GUI界面,用户可以输入发件人邮箱、授权码、收件人邮箱、邮件主题和内容。程序利用smtplib和email.mime.text模块实现邮件发送功能。
import tkinter
import smtplib
from email.mime.text import  MIMEText
class Send_email():
    def __init__(self):
        #初始化进行页面搭建
        window = tkinter.Tk()
        # 窗口大小
        window.geometry("300x300")
        # 禁止拉伸
        window.resizable(width=False, height=False)
        # 添加标题
        window.title("邮件发送")
        label = tkinter.Label(window, text = "邮箱主题")
        label.pack()
        #输入框 主题
        self.tittle_input = tkinter.Entry(window, width = '50')
        self.tittle_input.pack()
        #输入框 内容
        label = tkinter.Label(window, text="邮件内容")
        label.pack()
        self.content_input = tkinter.Entry(window, width='50')
        self.content_input.pack()
        #输入框 发件人邮箱
        label = tkinter.Label(window, text="发件人")
        label.pack()
        self.user_input = tkinter.Entry(window, width='50')
        self.user_input.pack()
        # 输入框 发件人授权码
        label = tkinter.Label(window, text="授权码")
        label.pack()
        self.pwd_input = tkinter.Entry(window, width='50')
        self.pwd_input.pack()

        # 输入框 收件人邮箱
        label = tkinter.Label(window, text="收件人")
        label.pack()
        self.to_input = tkinter.Entry(window, width='50')
        self.to_input.pack()
        #按钮
        btn = tkinter.Button(window, text = '发送', width = '30', command =self.send)
        btn.pack()
        window.mainloop()

    def send(self):
        user = self.user_input.get()
        to = self.to_input.get()
        pwd = self.pwd_input.get()
        content =self.content_input.get()
        title =self.tittle_input.get()
        server = "smtp.qq.com"
        message = MIMEText(content)
        message["subject"] = title # 设置主题
        message["From"] = user  # 发件人
        smtp_email = smtplib.SMTP(server, 25)  # 定义邮箱服务器
        smtp_email.login(user=user, password=pwd)  # 登陆邮箱
        smtp_email.sendmail(user,to, message.as_string())  # 发送
if __name__ == '__main__':
    sendmail = Send_email()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值