返回列表 发帖

Windows2012R2安装Python3

先安装Windows2012R2安装Python3时需要的补丁

备注:先安装KB2919442 ,再安装KB2919355,最后安装KB3118401
图片1.png
2020-5-12 22:31


KB2919442: https://pan.baidu.com/s/1fdyOw9EZVygY6cyR7bGEjw  提取码:679c
KB2919355: https://pan.baidu.com/s/1l4OLCKGl_c6L5PAIml5Pjw  提取码:dlg3
KB3118401: https://pan.baidu.com/s/1USTHlbNFUSCb6dckZYyKlg  提取码:scre

安装完补丁后,需要重启操作系统的。





######

安装Python3::(软件有32位/64位之分)
图片2.png
2020-5-12 22:31


要先勾选“Add Python 3.6 to PATH”:
图片3.png
2020-5-12 22:32


安装成功了:
图片4.png
2020-5-12 22:32






######

使用Notepad++编辑器创建一个Python脚本:

选择语言:
图片6.png
2020-5-12 22:33



选择编码:
图片7.png
2020-5-12 22:33




写一个发送邮件的脚本:(使用新浪邮箱的465端口+网址链接+附件)
#coding=utf-8

import smtplib #以下4个模块都是内置的,不用额外安装
from email.mime.text import MIMEText
from email.utils import formataddr
from email.mime.multipart import MIMEMultipart #发送附件的模块

my_sender = 'j2270168881@sina.com' #发件人邮箱账号
my_pass = '9157d00e9886890e' #发件人邮箱的授权码;新浪邮箱要使用授权码
my_name = 'zhuohua' #发件人邮箱昵称

receiver = '2270168881@qq.com' #收件人邮箱账号
receiver_name = 'Python' #收件人昵称


def func_mail():

        try:
       
                #创建一个带附件的实例
                Message_1 = MIMEMultipart()

                #构造附件1 (对应文件D:\test1.txt
                att1 = MIMEText(open('D:/test1.txt', 'rb').read(), 'base64', 'utf-8')
                att1["Content-Type"] = 'application/octet-stream'
                att1["Content-Disposition"] = 'attachment; filename="test1.txt"' #附件名称不包含中文时的写法;
                Message_1.attach(att1)

                #构造附件2 (对应文件D:\test2.log
                att2 = MIMEText(open('D:/test2.log', 'rb').read(), 'base64', 'utf-8')
                att2["Content-Type"] = 'application/octet-stream'
                att2.add_header("Content-Disposition","attachment",filename=("utf-8","","日志文件_test2.log")) #附件名称包含中文时的写法;附件的名称可以跟原文件的不一样
                Message_1.attach(att2)
               
               
                Key_1 = """

                <p>Welcome to zhuohua.</p>
                <p>...发送HTML格式的邮件...</p>

                <p><a href="http://blog.zhuohua.store">这是一个网址链接,跳转到站点 blog.zhuohua.store</a></p>

                """ #邮件的正文内容

               
                Message_1.attach(MIMEText(Key_1, 'html', 'utf-8')) #邮件正文内容使用网址链接;邮件有附件

                Message_1['From'] = formataddr([my_name,my_sender])
                Message_1['To'] = formataddr([receiver_name,receiver])
                Message_1['Subject'] = "新浪邮箱的465端口测试发送HTML格式的邮件(含附件)" #邮件的主题
               
                server = smtplib.SMTP_SSL("smtp.sina.com",465)  #发件人邮箱的SMTP服务器,端口是TCP 465       
                server.login(my_sender, my_pass)
                server.sendmail(my_sender,[receiver,],Message_1.as_string())
                server.quit()
               
        except Exception as e:
                print (f"发送邮件失败,原因: {e}")
               
        else:
                print("Welcome to zhuohua\n邮件发送成功")


if __name__ == '__main__':

        func_mail()


保存:
图片9.png
2020-5-12 22:33


Python脚本创建成功:
图片10.png
2020-5-12 22:34




运行Python脚本:
C:\Users\Administrator>cd Desktop

C:\Users\Administrator\Desktop>python xx.py
Welcome to zhuohua
邮件发送成功


C:\Users\Administrator\Desktop>

如下图:(按以上的配置,脚本是支持中文的)
图片1.png
2022-3-26 10:26



QQ邮箱收到的邮件:
图片2.png
2022-3-26 10:27


笺注:
附件可以正常下载、打开;附件的内容可以包含中文。
点击网址链接会跳转到http://blog.zhuohua.store





相关文章:
邮件使用网址链接可参考:Win10安装Python3
邮件使用附件可参考:Python3使用新浪邮箱的25端口发送邮件

Python3使用Virtual Environment
Python3脚本管理MSSQL2014

Zabbix调用Python3脚本监控MSSQL
Windows2012R2_UPUPW_网站的备份和还原(使用Python3脚本)

Win7/Windows2008R2安装Python3







#################################
#################################
亲,学习研究也要劳逸结合哦,来我微店逛逛,买点东西好好犒劳犒劳自己和家人吧^_^^_^

苏泊尔多功能电热锅韩式电火锅8-10人家用电炒锅不粘锅电锅电烤锅
guo.png
2020-5-19 14:14


苏泊尔电火锅多功能家用电热锅不沾锅一体电煮锅宿舍4-6人
huoguo.png
2020-5-19 14:15

返回列表