Because recently do Buildbot, want to use the company's mail system Lotus Notes to send mail, but there are no more complete examples on the Internet, are more examples of VB, or incomplete examples, and then see a Visual FoxPro to do the example, just know Lotus COM objects may differ between versions, such as many examples on the Internet using Doc. form, but in fact the Doc object has no form attribute and should be replaceitemvalue. This example is for notes 6.5.
From win32com.client import Dispatch
def sendemail (Sendto,cc,bcc,subject,body,attachment=none,pass=none):
If Sendto==none:
Return
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")