Use Python to drive Lotus Notes to send mail

Source: Internet
Author: User

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

Related Article

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.