Python 发邮件

Python发邮件

PS: 也是从网上各个帖子中学习的Python,因此代码的格式以及内容有粘贴网上其他大神的代码,如有侵权请告知删除

示例图片
在这里插入图片描述

#!/usr/bin/python
# -*- coding: UTF-8 -*-

# 邮件模块
import  smtplib
from  email.mime.text import  MIMEText
import time
from tkinter import *
import tkinter.filedialog

root = Tk()
root.geometry('400x400')

def SendMail():
    # 163邮箱的地址
    mail163Url = Sentence1.get()
    # 163邮箱服务器的端口号
    mail163Port = Sentence2.get().

    # 发件箱地址
    userMail = Sentence3.get()
    # 授权密码,不是登录密码
    passwd = Sentence4.get()

    # 收件人地址
    toMail = Sentence5.get()

    # 连接邮箱服务器, 获得服务器对象
    smtpServer = smtplib.SMTP(mail163Url, mail163Port)

    # 登陆邮箱服务器
    smtpServer.login(userMail, passwd)

    # 编辑邮箱内容 — 收件人, 发件人, 主题…
    mineText = MIMEText(Sentence7.get())

    # 设置主题
    mineText['Subject'] = Sentence6.get()

    # 设置收件人
    mineText['To'] = toMail

    # 设置发件人
    mineText['From'] = Sentence8.get()

    # 发送邮件
    for i in range(1, 6):
        smtpServer.sendmail(userMail, toMail, mineText.as_string())
        time.sleep(2)

    # 关闭连接
    smtpServer.close()

# -------------------------------------界面---------------------------------
Text1 = Label(root, text='邮箱类型:')
Text1.grid(row=1, sticky=W)
Sentence1 = Entry(root)
Sentence1.grid(row=1, column=1, sticky=W)

Text2 = Label(root, text='邮箱服务器端口号:')
Text2.grid(row=2, sticky=W)
Sentence2 = Entry(root)
Sentence2.grid(row=2, column=1, sticky=W)

Text3 = Label(root, text='登录邮箱名:')
Text3.grid(row=3, sticky=W)
Sentence3 = Entry(root)
Sentence3.grid(row=3, column=1, sticky=W)

Text4 = Label(root, text='登录邮箱授权码:')
Text4.grid(row=4, sticky=W)
Sentence4 = Entry(root)
Sentence4.grid(row=4, column=1, sticky=W)

Text5 = Label(root, text='收件人邮箱地址:')
Text5.grid(row=5, sticky=W)
Sentence5 = Entry(root)
Sentence5.grid(row=5, column=1, sticky=W)

Text6 = Label(root, text='邮件主题:')
Text6.grid(row=6, sticky=W)
Sentence6 = Entry(root)
Sentence6.grid(row=6, column=1, sticky=W)

Text7 = Label(root, text='邮件内容:')
Text7.grid(row=7, sticky=W)
Sentence7 = Entry(root)
Sentence7.grid(row=7, column=1, sticky=W)

Text8 = Label(root, text='显示发件人:')
Text8.grid(row=8, sticky=W)
Sentence8 = Entry(root)
Sentence8.grid(row=8, column=1, sticky=W)

Action = Button(root, text="执行", command=SendMail)
Action.grid(row=9, column=0, sticky=W)

root.mainloop()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值