Because buildbot recently wanted to use the company's mail system Lotus Notes to send emails, but there were no complete examples on the Internet. There were many examples of VB or incomplete examples, later, I saw an example using Visual FoxPro to know that the COM objects of Lotus may have different versions. For example, many examples on the Internet use Doc. form, but in fact, the doc object does not have the form attribute, so replaceitemvalue should be used. 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; charsets = 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; charsets = 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 ")