Use python to drive Lotus Notes to send emails

Source: Internet
Author: User

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 ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.