windows 10
Notes版本:9.0.1
原理是python调用win32 的com 组件发送邮件,所以和notes客户端的版本有关系。
用到Python库 pywin32
pip install pywin32
服务器:
如图下,比如SZdom/szABCtech, 脚本里面写的时候为SZdom@szABCtech
邮件数据库:
数据库为:mail\你的邮件名
收件人:
User1/szABCtech
#! 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.5
class 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.OPENMAIL
except 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.CREATEDOCUMENT
doc.sendto = reciver_list
doc.Subject = subject
if body:
doc.Body = body
doc.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