In this post, we will be providing you with a script that you can use, if you have Lotus notes as your preferred emailing option.
Note: You will need to have Lotus Notes installed for this to work
The Code
Public Function SendEmailFromLotusNotes(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean) As Boolean On Error GoTo ErrorHandler SendEmailFromLotusNotes = False '-------------------------------------------------------------------------------' ' ' Sends an email via Lotus Notes. '------------------------------------------------------------------------------- '-------------------------------------------------------------------------------' ' To send an email to more than one person you will need to pass in the email ' addresses in this format: ' "steve@hotmail.com;ian@yahoo.com;john@gmail.com" ' Please note the use of the ";" to separate the email addresses '-------------------------------------------------------------------------------' 'Set up the objects required for Automation into lotus notes Dim Maildb As Object 'The mail database Dim Username As String 'The current users notes name Dim MailDbName As String 'THe current users notes mail database name Dim MailDoc As Object 'The mail document itself Dim AttachME As Object 'The attachment richtextfile object Dim MailSession As Object 'The notes session Dim EmbedObj As Object 'The embedded object (Attachment) Dim strSendTo() As String If Recipient = "-1" Or Recipient = "" Then Err.Raise -100, , "Unable to get email addresses." strSendTo = Split(Recipient, ";") 'Start a session to notes Set MailSession = CreateObject("Notes.NotesSession") 'Get the sessions username and then calculate the mail file name 'You may or may not need this as for MailDBname with some systems you 'can pass an empty string Username = MailSession.Username MailDbName = Left$(Username, 1) & Right$(Username, (Len(Username) - InStr(1, Username, " "))) & ".nsf" 'Open the mail database in notes Set Maildb = MailSession.GETDATABASE("", MailDbName) If Maildb.IsOpen = True Then 'Already open for mail Else Maildb.OPENMAIL End If 'Set up the new mail document Set MailDoc = Maildb.CREATEDOCUMENT MailDoc.Form = "Memo" MailDoc.sendto = strSendTo MailDoc.Subject = Subject MailDoc.Body = BodyText MailDoc.SAVEMESSAGEONSEND = SaveIt 'Set up the embedded object and attachment and attach it If Attachment <> "" Then Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment") Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment") MailDoc.CREATERICHTEXTITEM ("Attachment") End If 'Send the document MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder MailDoc.Send 0, strSendTo SendEmailFromLotusNotes = True ExitFunction: 'Clean Up Set Maildb = Nothing Set MailDoc = Nothing Set AttachME = Nothing Set MailSession = Nothing Set EmbedObj = Nothing Exit Function ErrorHandler: SendEmailFromLotusNotes = False Resume ExitFunction End Function
The Explanation
The code in the above function is similar in conception to the code for automating MS Outlook. the objects may be different but the ideas remain the same.
The Conclusion
In this post, we have provided you with a script to automate Lotus Notes from MS Access.