Python - IBM Notes 发送邮件
生活随笔
收集整理的這篇文章主要介紹了
Python - IBM Notes 发送邮件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
0. 環境說明
windows 10
Notes版本:9.0.1
原理是python調用win32 的com 組件發送郵件,所以和notes客戶端的版本有關系。
1. 安裝插件
用到Python庫 pywin32
pip install pywin322. 配置查找
服務器:
如圖下,比如SZdom/szABCtech, 腳本里面寫的時候為SZdom@szABCtech
郵件數據庫:
數據庫為:mail\你的郵件名
收件人:
User1/szABCtech
3. 代碼
#! python3 # _*_ coding:utf-8 _*_"""IBM notes send email Max.Bai """# notes 9.0 from win32com.client import DispatchEx from win32com.client import makepy makepy.GenerateFromTypeLibSpec('Lotus Domino Objects')# from win32com.client import DispatchEx # notes 8.5class NotesMail(object):def __init__(self, server, file):print('init mail client')self.session = DispatchEx('Notes.NotesSession')# self.server = self.session.GetEnvironmentString("MailServer", True)self.db = self.session.GetDatabase(server, file)if not self.db.IsOpen:print('open mail db')try:self.db.OPENMAILexcept Exception as e:print(str(e))print( 'could not open database: {}'.format(db_name) )# for notes 8.5 maybe# session = DispatchEx('Lotus.NotesSession')# session.Initialize(pwd)# self.db = session.getDatabase(server, file)# if not self.db.IsOpen:# try:# self.db.Open()# except pywintypes.com_error:# print( 'could not open database: {}'.format(db_name) )def send_mail(self, reciver_list, subject, body=None):doc = self.db.CREATEDOCUMENTdoc.sendto = reciver_listdoc.Subject = subjectif body:doc.Body = bodydoc.SEND(0, reciver_list)print('send success')def main():# recivers = ['User1/szABCtech', 'User2/szABCtech']recivers = ['User1/Szhittech']mail = NotesMail('dominoserver@szABCtech', 'mail\User1')mail.send_mail(recivers, 'test sender', 'This is a test mail body ')if __name__ == '__main__':main()4. 參考鏈接
https://github.com/LeoLuo22/notesmail/blob/master/notesmail.py#L7
總結
以上是生活随笔為你收集整理的Python - IBM Notes 发送邮件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Notes 12.0.1邮箱模板修复的几
- 下一篇: websocket python爬虫_p