• [软件工程]python 发送邮件网易邮箱163示范


    首先申请163邮箱账号

    打开smtp服务,设置授权码

        my_sender = '发件人邮箱'  # 发件人邮箱账号,为了后面易于维护,所以写成了变量
        my_user = '收件人邮箱'  # 收件人邮箱账号,为了后面易于维护,所以写成了变量
        try:
            msg = MIMEText('填写邮件内容', 'plain', 'utf-8')
            msg['From'] = formataddr(["FriendReader", my_sender])  # 括号里的对应发件人邮箱昵称、发件人邮箱账号
            msg['To'] = formataddr(["收件人邮箱昵称", my_user])  # 括号里的对应收件人邮箱昵称、收件人邮箱账号
            msg['Subject'] = "主题"  # 邮件的主题,也可以说是标题
    
            server = smtplib.SMTP("smtp.163.com", 25)  # 发件人邮箱中的SMTP服务器,端口是25
            server.login(my_sender, "授权码")  # 括号中对应的是发件人邮箱账号、邮箱密码
            server.sendmail(my_sender, [my_user, ], msg.as_string())  # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
            server.quit()  # 这句是关闭连接的意思
            print("邮件发送成功")
        except smtplib.SMTPException:
            print("Error: 无法发送邮件")

    发送完成的效果图为

  • 相关阅读:
    [CF598E] Chocolate Bar
    [CF629D] Babaei and Birthday Cake
    [CF961D] Pair Of Lines
    [CF468B] Two Sets
    [CF767C] Garland
    [CF864E] Fire
    [CF578C] Weakness and Poorness
    [CF555B] Case of Fugitive
    [CF118E] Bertown roads
    [CF1301D] Time to Run
  • 原文地址:https://www.cnblogs.com/HITLJR/p/8016820.html
Copyright © 2020-2023  润新知