本文共 1694 字,大约阅读时间需要 5 分钟。
以下是我为您提供的一段用于通过Lotus Notes发送邮件的代码示例:
from __future__ import division, print_functionimport osimport uuidfrom win32com.client import DispatchEximport pywintypesdef send_mail(subject, body_text, sendto, copyto=None, blindcopyto=None, attach=None): session = DispatchEx('Lotus.NotesSession') session.Initialize('your_password') server_name = 'your/server' db_name = 'your/database.nsf' db = session.getDatabase(server_name, db_name) if not db.IsOpen: try: db.Open() except pywintypes.com_error: print(f'could not open database: {db_name}') return doc = db.CreateDocument() doc.ReplaceItemValue("Form", "Memo") doc.ReplaceItemValue("Subject", subject) uid = str(uuid.uuid4().hex) doc.ReplaceItemValue('UNIVERSALID', uid) doc.ReplaceItemValue("SendTo", sendto) if copyto is not None: doc.ReplaceItemValue("CopyTo", copyto) if blindcopyto is not None: doc.ReplaceItemValue("BlindCopyTo", blindcopyto) body = doc.CreateRichTextItem("Body") body.AppendText(body_text) if attach is not None: attachment = doc.CreateRichTextItem("Attachment") for att in attach: attachment.EmbedObject(1454, "", att, "Attachment") doc.SaveMessageOnSend = True doc.Send(False)if __name__ == '__main__': subject = "test subject" body = "test body" sendto = ['abc@def.com'] files = ['/path/to/a/file.txt', '/path/to/another/file.txt'] attachment = list(filter(os.path.exists, files)) send_mail(subject, body, sendto, attach=attachment) 该代码示例旨在通过Lotus Notes发送电子邮件,支持附件和多个收件人。代码结构清晰,注重易读性和功能性,适合在实际应用中使用。
转载地址:http://gqofk.baihongyu.com/