Exemple #1
0
def week_report_xls():
    ''' 生成 excel 表
    '''
    import date
    import datetime
    import pyMail
    weekreport_name = "/opt/weekreport.xls"
    d = datetime.datetime.now()
    date_from,date_to = date.week_get(d)
    print date_from,date_to
    terminal_table = False
    zabbix=zabbix_api(terminal_table)
    itemkey_list=['vm.memory.size[available]', 'agent.ping', 'vfs.fs.size[/,pfree]', 'system.cpu.load[percpu,avg1]']
    export_xls = {"xls":"ON",
                  "xls_name":weekreport_name,
                  "title":"ON",
                  "title_name":u"周报"
    }
    select_condition = {"hostgroupID":"",
            "hostID":""
    }
    zabbix._report_available2(str(date_from),str(date_to),export_xls,select_condition,itemkey_list=itemkey_list)
    
    # 1 初始化发送邮件类
    # 25 端口时,usettls = False
    # 465 端口时,usettls = True
    usettls = False
    sml = pyMail.SendMailDealer('mail_address','mail_pwd','smtp.gmail.com','25',usettls = usettls)
    # 2 设置邮件信息
    # 参数包括("收件人","标题","正文","格式html/plain","附件路径1","附件路径2")
    sml.setMailInfo('*****@*****.**','测试','正文','plain',weekreport_name)
    # 3 发送邮件
    sml.sendMail()
Exemple #2
0
# -*- coding: utf-8 -*
import pyMail

#初始化接收邮件类
rml = pyMail.ReceiveMailDealer('mail_address','mail_pwd','imap.gmail.com')
rml.select('INBOX')
#获取未读邮件列表
print(rml.getUnread())#('OK',['1 2 3 4'])
#遍历未读邮件
for num in rml.getUnread()[1][0].split(' '):
    if num != '':   
        mailInfo = rml.getMailInfo(num)
        print(mailInfo['subject'])
        print(mailInfo['body'])
        print(mailInfo['html'])
        print(mailInfo['from'])
        print(mailInfo['to'])
        #遍历附件列表
        for attachment in mailInfo['attachments']:
            fileob = open(attachment['name'],'wb')
            fileob.write(attachment['data'])
            fileob.close()

#初始化发送邮件类
sml = pyMail.SendMailDealer('mail_address','mail_pwd','smtp.gmail.com', 587)
#设置邮件信息
sml.setMailInfo('*****@*****.**','测试','正文','plain','/home/paramiao/resume.html')
#发送邮件
sml.sendMail()
Exemple #3
0
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*
import pyMail
import getpass
import time
import os
import filename

# 推荐使用qq邮箱
username = raw_input("User: "******"smtp server: ")
imap_server = raw_input("imap server: ")

# 初始化发送邮件类
sml = pyMail.SendMailDealer(username, passwd, smtp_server, 25)
# 设置邮件信息
sml.setMailInfo(username, u'标题', u'正文', 'plain', './README.md')
# 发送邮件
sml.sendMail()

# 初始化接收邮件类
rml = pyMail.ReceiveMailDealer(username, passwd, imap_server)

account_dir = os.getcwd() + '/email/' + username

rml.select('INBOX')

box_dir = account_dir + '/' + 'INBOX'

os.makedirs(box_dir, exist_ok=True)