展开全部
from win32com.client import Dispatch
def SendEmail(SendTo, CC, BCC, Subject, Body, Attachment=None, Pass=None):
if SendTo==None:
e69da5e6ba9062616964757a686964616f31333339663362return
session=Dispatch("Lotus.NotesSession")
if Pass:
session.Initialize(Pass)
Server=session.GetEnvironmentString( "MailServer",True)
MaildbName=session.GetEnvironmentString( "MailFile",True)
db=session.GetDatabase(Server,MaildbName)
doc=db.CreateDocument()
doc.ReplaceItemValue("Form","Memo")
if SendTo:
doc.ReplaceItemValue("SendTo",SendTo)
if CC:
doc.ReplaceItemValue("CopyTo",SendTo)
if BCC:
doc.ReplaceItemValue("BlindCopyTo",SendTo)
if Subject:
doc.ReplaceItemValue("Subject",Subject)
stream=session.CreateStream()
stream.WriteText(Body)
bodyMime=doc.CreateMIMEEntity()
bodyMime.SetContentFromText(stream,"text/html;charset=iso-8859-1",False)
if Attachment:
RichTextItem = doc.CreateRichTextItem("Attachment")
for fn in Attachment:
RichTextItem.EmbedObject(1454, "", fn ,"Attachment")
'''
bodyMime=doc.CreateMIMEEntity()
bodyMime.SetContentFromText(stream,"text/html;charset=iso-8859-1",False)
doc.ReplaceItemValue( "Logo", "StdNotesLtr3" )
doc.ReplaceItemValue( "_ViewIcon", 23 )
doc.ReplaceItemValue( "SenderTag", "Y" )
'''
doc.Send(False)
SendEmail("yourname@yourdomain",None,None,"Title:test for python","body:test for python send mail",
["d:/testtool/teri/pcsim/test.xls","d:/testtool/teri/pcsim/test_email.py"],"password")
可以看下这段代码,电脑没有notes邮箱,未测试
PS:需要下载对应版本的pywin32