pythonoutlook
最近有个需求就是页面上执行shell命令,第一想到的就是os.system,
复制代码代码如下没旦:
os.system('cat /proc/cpuinfo')
但是发现页面上打印的命令执行结果 0或者1,当然不满足需求了。
尝试第二种方案 os.popen()
复制代码代码如下宴察卖:
output = os.popen('cat /proc/cpuinfo')
print output.read()
通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出。但是无法读取程序晌逗执行的返回值)
尝试第三种方案 commands.getstatusoutput() 一个方法就可以获得到返回值和输出,非常好用。
复制代码代码如下:
(status, output) = commands.getstatusoutput('cat /proc/cpuinfo')
print status, output
Python Document 中给的一个例子,
复制代码代码如下:
>>> import commands
>>> commands.getstatusoutput('ls /bin/ls')
(0, '/bin/ls')
>>> commands.getstatusoutput('cat /bin/junk')
(256, 'cat: /bin/junk: No such file or directory')
>>> commands.getstatusoutput('/bin/junk')
(256, 'sh: /bin/junk: not found')
>>> commands.getoutput('ls /bin/ls')
'/bin/ls'
>>> commands.getstatus('/bin/ls')
'-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls'
最后页面上还可以根据返回值来显示命令执行结果。
2. 如何在python等脚本中调用outlook组件
范例代码如下:
importwin32com.client
defsend_mail_via_com(text,subject,recipient,profilename="Outlook2003"团备肢孙):
s=win32com.client.Dispatch("Mapi.Session")
o=win32com.client.Dispatch("Outlook.Application")
s.Logon(profilename)
Msg=o.CreateItem(0)
Msg.To=recipient
塌饥毁
Msg.CC="moreaddresseshere"
Msg.BCC="address"
Msg.Subject=subject
Msg.Body=text
attachment1="Pathtoattachmentno.1"
attachment2="Pathtoattachmentno.2"
Msg.Attachments.Add(attachment1)
Msg.Attachments.Add(attachment2)
Msg.Send()
3. 麻烦用python写一个outlook收发邮件
去清裤举网上搜一下,down一个参考一下。python还是比较新的内容,你学它做自纯袭动答碧化测试之类的,还是不错的。
4. python用outlook发送附件怎么发送utlook是内网
outlook撤回或删掉正在烂扮尺发送的邮件饥高的步骤:在正在发送邮件时,选中右下角的【正在准备缺并发送/接收】,鼠标右键选择【取消 发送/接收】。
5. 如何通过python发送日历邮件
方便起见,用代码说话(只是最简单的版本,各种定制需求可以参看rfc,不过很多效果需要客户端的支持,支持的比较好的是outlook)
# encoding: utf-8
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
import os,datetime
def send_email(**kwargs):
"""
method
event
dtstart
e
msg
dtstamp
"""
ical = """
BEGIN:VCALENDAR\r\n
PRODID:pyICSParser\r\n
METHOD:%(method)s\r\n
VERSION:2.0\r\n
BEGIN:%(event)s\r\n
DTSTART:%(dtstart)s\r\n
DUE:%(e)s\r\n
PRIORITY:1\r\n
SUMMARY:%(msg)s\r\n
UID:[email protected]\r\n
SEQUENCE:0\r\n
DTSTAMP:%(dtstamp)s\r\n
STATUS:%(status)s\r\n
END:VEVENT\r\n
END:VCALENDAR\r\n
"""% kwargs
eml_body = u"%(msg)s" % kwargs
msg = MIMEMultipart('mixed')
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = u"%(msg)s" % kwargs
msg['To'] = ",".join(attendees)
part_email = MIMEText(eml_body,"html",'utf-8')
part_cal = MIMEText(ical,'calendar;method=%(method)s'%kwargs,'utf-8')
msgAlternative = MIMEMultipart('alternative')
msg.attach(msgAlternative)
ical_atch = MIMEBase('application/ics',' ;name="%s"'%("invite.ics"))
ical_atch.set_payload(ical)
Encoders.encode_base64(ical_atch)
ical_atch.add_header('Content-Disposition', 'attachment; filename="%s"'%("invite.ics"))
eml_atch = MIMEBase('text/plain','')
Encoders.encode_base64(eml_atch)
eml_atch.add_header('Content-Transfer-Encoding', "")
msgAlternative.attach(part_email)
msgAlternative.attach(part_cal)
s = smtplib.SMTP()
s.connect('xxxx')
s.login(' ', ' ')
s.sendmail('[email protected]', attendees, msg.as_string())
s.close()
attendees =['[email protected]']
fro = ""
ddtstart = datetime.datetime.utcnow()
r = datetime.timedelta(minutes= 5)
dtend = ddtstart + r
dtend = dtend.strftime("%Y%m%dT%H%M%SZ")
send_email(method='PUBLISH',event='VTODO',dtstart=dtend,e=dtend,msg='publish 任务',dtstamp=dtend, status="COMPLETED")
send_email(method='REQUEST',event='VTODO',dtstart=dtend,e=dtend,msg='request 任务',dtstamp=dtend, status="NEEDS ACTION")
send_email(method='PUBLISH',event='VEVENT',dtstart=dtend,e=dtend,msg='publish 日历',dtstamp=dtend, status="CONFIRMED")
send_email(method='REQUEST',event='VEVENT',dtstart=dtend,e=dtend,msg='request 日历',dtstamp=dtend, status='CONFIRMED')
6. python 发送邮件
以下脚本测试通过!!!!!
fromTkinterimportTk
fromtimeimportsleep
importwin32com.clientaswin32
warn=lambdaapp:showwarning(app,"Exit?")
Range=range(3,8)
defoutlook():
app="Outlook"
olook=win32.gencache.EnsureDispatch("%s.Application"%app)
mail=olook.CreateItem(win32.constants.olMailItem)
recip=mail.Recipients.Add("[email protected]")
subj=mail.Subject="Python-to-%sDemo"%app
body=["Line%d"%iforiinRange]
body.insert(0,"%s "%subj)
body.append(" Th-th-th-that'sallfolks!")
mail.Body=" ".join(body)
mail.Send()
'''
ns=olook.GetNamespace("MAPI")
obox=ns.GetDefaultFolder(win32.constants.olFolderOutbox)
obox.Display()
obox.Items.Item(1).Display()
'''
warn(app)
olook.Quit()
if__name__=="__main__":
Tk().withdraw()
outlook()
7. mac python outlook内容换行怎么实现
运用图表上的
来实现换行。
在我们平时打字聊天中,我们的换行很直接,点回车即可。那在python中我们要操作这种方式要怎么处理呢,输入一个例子。第一种自动换行,我们可以跟我们平时打字那样操作,但这样操作会出现错误。你这个时候可以试着把单引号或者双引号修改成三引号,发现这次是可以运行的。除了上面的方式,我们还可以使用转义符,针对这个符号我们可以看一下这个图表。运用图表上的
来实现换行,但需要注意的是,你可以用单引号和三引号,但用双引号这里要出现语法错误。
Python解释器易于扩展,可以使用C语言或C+(或者其他可以通过C调用的语言)扩展新的功能和数据类型。Python也可用于可定制化软件中的扩展程序语言。Python丰富的标准库,提供了适用于各个主要系统平台的源码或机器码。
8. python对outlook邮件读取
鉴于周报都要读取不同邮件内容,想定时运行便于操作。
一些相关性质记录:
写邮件:
尚存问题:
2.附件没法直接读取,要保存后再读取,尚需探索。