def send_mail(subject, body_text, sendto, copyto=None, blindcopyto=None, attach=None): # Get credentials mailServer = 'Your Server' mailPath = 'Your database' mailPassword = '******' # Connect notesSession = DispatchEx('Lotus.NotesSession') try: notesSession.Initialize(mailPassword) notesDatabase = notesSession.GetDatabase(mailServer, mailPath) except pywintypes.com_error: raise Exception('Cannot access mail using %s on %s' % (mailPath, mailServer)) # print('Title:' + notesDatabase.Title) # Get a list of folders # for view in notesDatabase.Views: # if view.IsFolder: # print('view : ' + view.Name) document = notesDatabase.CreateDocument() document.ReplaceItemValue("Form", "Memo") document.ReplaceItemValue("Subject", subject) # assign random uid because sometimes Lotus Notes tries to reuse the same one uid = str(uuid.uuid4().hex) document.ReplaceItemValue('UNIVERSALID', uid) # "SendTo" MUST be populated otherwise you get this error: # 'No recipient list for Send operation' document.ReplaceItemValue("SendTo", sendto) if copyto is not None: document.ReplaceItemValue("CopyTo", copyto) if blindcopyto is not None: document.ReplaceItemValue("BlindCopyTo", blindcopyto) # body body = document.CreateRichTextItem("Body") body.AppendText(body_text) # attachment if attach is not None: attachment = document.CreateRichTextItem("Attachment") for att in attach: attachment.EmbedObject(1454, "", att, "Attachment") # save in `Sent` view; default is False document.SaveMessageOnSend = True document.Send(False)
def 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('could not open database: {}'.format(db_name)) doc = db.CreateDocument() doc.ReplaceItemValue("Form", "Memo") doc.ReplaceItemValue("Subject", subject) # assign random uid because sometimes Lotus Notes tries to reuse the same one uid = str(uuid.uuid4().hex) doc.ReplaceItemValue('UNIVERSALID', uid) # "SendTo" MUST be populated otherwise you get this error: # 'No recipient list for Send operation' doc.ReplaceItemValue("SendTo", sendto) if copyto is not None: doc.ReplaceItemValue("CopyTo", copyto) if blindcopyto is not None: doc.ReplaceItemValue("BlindCopyTo", blindcopyto) # body body = doc.CreateRichTextItem("Body") body.AppendText(body_text) # attachment if attach is not None: attachment = doc.CreateRichTextItem("Attachment") for att in attach: attachment.EmbedObject(1454, "", att, "Attachment") # save in `Sent` view; default is False doc.SaveMessageOnSend = True doc.Send(False)
def getDatabase(server, filePath, password): # Connect notesSession = DispatchEx('Lotus.NotesSession') try: notesSession.Initialize(password) notesDatabase = notesSession.GetDatabase(server, filePath) if not notesDatabase.IsOpen: try: notesDatabase.Open() except pywintypes.com_error: print('could not open database: {}'.format(db_name)) return notesDatabase except pywintypes.com_error: raise Exception('Cannot access database using %s on %s' % (filePath, server))
while document: # Yield it yield document # Get the next document document = folder.GetNextDocument(document) if __name__ == '__main__': # Get credentials mailServer = 'Your Server' mailPath = 'Your database' mailPassword = '******' # Connect notesSession = DispatchEx('Lotus.NotesSession') try: notesSession.Initialize(mailPassword) notesDatabase = notesSession.GetDatabase(mailServer, mailPath) except pywintypes.com_error: raise Exception('Cannot access mail using %s on %s' % (mailPath, mailServer)) # print('Title:' + notesDatabase.Title) # Get a list of folders # for view in notesDatabase.Views: # if view.IsFolder: # print('view : ' + view.Name) for document in makeDocumentGenerator('($Inbox)'): # Get fields subject = document.GetItemValue('Subject')[0].strip()
def send_mail(subject, body_text, send_to, copyto=None, blindcopyto=None, attachments=None): # connect to Notes COM session = DispatchEx('Lotus.NotesSession') while True: try: session.Initialize(input("Notes Password: "******""" for server_name and db_name from Notes: File > Preferences > Locations > Online > Edit server_name = Servers > Home/mail server db_name = Mail > Mail file """ 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}") # build document doc = db.CreateDocument() doc.ReplaceItemValue("Form", "Memo") doc.ReplaceItemValue("Subject", subject) # assign random uid because sometimes Lotus Notes tries to reuse the same one uid = str(uuid.uuid4().hex) doc.ReplaceItemValue('UNIVERSALID', uid) # "SendTo" MUST be populated otherwise you get this error: # 'No recipient list for Send operation' doc.ReplaceItemValue("SendTo", send_to) if copyto: doc.ReplaceItemValue("CopyTo", copyto) if blindcopyto: doc.ReplaceItemValue("BlindCopyTo", blindcopyto) # body body = doc.CreateRichTextItem("Body") body.AppendText(body_text) # attachments if attachments: email_att_field = doc.CreateRichTextItem("Attachment") for attachment in attachments: email_att_field.EmbedObject(1454, "", attachment, "Attachment") doc.SaveMessageOnSend = True # show sent email in Notes "Sent" view doc.Send( False ) # not really sure what the arg is for, but makes file sizes massive if True