VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Create and send Lotus Notes email using COM

by Todd Benson (3 Submissions)
Category: OLE/COM/DCOM/Active-X
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (9 Votes)

'
' Creates & sends an email via Lotus Notes 5.0 & up. Also, allows creating/sending even with Lotus Notes not running (although it MUST be loaded on the local machine)

Inputs
' ' Subject: Subject line of email ' Body: Body (text) of email ' SaveOnSend: True/False, save the email in the 'sent' box ' sendTO (OPTIONAL): the intended receipient of the email ' ccTO (OPTIONAL): the carbon-copied receipient of the email ' bccTO (OPTIONAL): the blind carbon-copied receipient of the email ' lnLogo (OPTIONAL): changes the bitmap logo on the header (0 = no logo) ' AttachmentPath (OPTIONAL): the path of the email attachement
Assumes
' ' Note: Although all sendto items are optional, if you don't use at least one of them, Lotus Notes won't send your email to any one and may return errors. ' ' Note: Make sure that Lotus Domino Objects is selected as an available reference. ' ' Note: If your Lotus Notes does NOT require a password, then remove the parenthetical ("*********") following 'Call ses.Initialize'
Code Returns
Returns true if no errors are encountered.

Rate Create and send Lotus Notes email using COM

Function CreateNewNotesMail(Subject As String, Body As String, SaveOnSend As Boolean, Optional sendTO As String, Optional ccTO As String, Optional bccTO As String, Optional lnLogo As Long, Optional AttachmentPath As String) As Boolean
 
 Dim ses As New NotesSession  'Notes Session
 Dim mailserver As Variant  'Variable for user's mail server
 Dim mailfile As Variant   'Variable for user's mail file
 Dim lnDatabase As Object  'Notes Database
 Dim lnDocument As Object  'Notes Document
 Dim lnRichText As Object  'Body of Document
 Dim lnAttachment As Object  'Notes Attachement
 On Error GoTo CreateNotesMail_Error
 ' --------------------------------------
 ' Create instantiation of Lotus Notes
 ' Pass Username & password
 ' You can prompt user for password
 ' using inputbox instead of hard coding
 ' password
 ' --------------------------------------
 Call ses.Initialize("*********")  'Replace your email password where the ********* is.
 'Debug.Print ses.UserName
 
 ' --------------------------------------
 ' Find out the name of the mail server
 ' Find out the name of the mail file
 ' --------------------------------------
 mailserver = ses.GETENVIRONMENTSTRING("Mailserver", True)
 mailfile = ses.GETENVIRONMENTSTRING("Mailfile", True)
 ' --------------------------------------
 ' Open the mail file on the mail server
 ' Create a new email document
 ' --------------------------------------
 Set lnDatabase = ses.GetDatabase(mailserver, mailfile)
 Set lnDocument = lnDatabase.CreateDocument
 Set lnRichText = lnDocument.CreateRichTextItem("Body")
 
 ' --------------------------------------
 ' Fill out the email text by adding
 ' data passed to the is module
 ' --------------------------------------
 Call lnRichText.AppendText(Body & Chr(13) & Chr(13))
 With lnDocument
  .ReplaceItemValue "SendTo", sendTO
  .ReplaceItemValue "CopyTo", ccTO
  .ReplaceItemValue "BlindCopyTo", bccTO
  .ReplaceItemValue "Subject", Subject
  .ReplaceItemValue "Logo", "StdNotesLtr" & Trim$(str$(lnLogo))
  If SaveOnSend = True Then .SaveMessageOnSend = True
 End With
 ' --------------------------------------
 ' Embed the email attachment, if any
 ' --------------------------------------
 If AttachmentPath <> "" Then
  Set lnAttachment = lnRichText.EMBEDOBJECT(1454, "", AttachmentPath)
 End If
 
 lnDocument.Send False
 CreateNewNotesMail = True
 
 ' --------------------------------------
 ' Clean up the code
 ' --------------------------------------
 Set lnDatabase = Nothing
 Set lnDocument = Nothing
 Set lnAttachment = Nothing
  
CreateNotesMail_Error:
 'Debug.Print Err.Description
 Exit Function
 
End Function

Download this snippet    Add to My Saved Code

Create and send Lotus Notes email using COM Comments

No comments have been posted about Create and send Lotus Notes email using COM. Why not be the first to post a comment about Create and send Lotus Notes email using COM.

Post your comment

Subject:
Message:
0/1000 characters