Creating email and attaching a file in lotus notes

By | 2002-06-01

This code is to show how to create an email in lotus notes with an attached file

Original Author: Stan Allan

Code

Private Sub CmdSend_Click()
Dim oSess As Object
Dim oDB As Object
Dim oDoc As Object
Dim oItem As Object
Dim direct As Object
Dim Var As Variant
Dim flag As Boolean
Form1.MousePointer = 11
Form1.StatusBar1.SimpleText = "Opening Lotus Notes..."
Set oSess = CreateObject("Notes.NotesSession")
Set oDB = oSess.GETDATABASE("", "")
Call oDB.OPENMAIL
flag = True
If Not (oDB.ISOPEN) Then flag = oDB.OPEN("", "")
If Not flag Then
MsgBox "Can't open mail file: " & oDB.SERVER & " " & oDB.FILEPATH
GoTo exit_SendAttachment
End If
On Error GoTo err_handler
Form1.StatusBar1.SimpleText = "Building Message"
Set oDoc = oDB.CREATEDOCUMENT
Set oItem = oDoc.CREATERICHTEXTITEM("BODY")
oDoc.Form = "Memo"
oDoc.subject = Form1.TxtSubject.Text
oDoc.sendto = Form1.TxtSendTo.Text
oDoc.body = Form1.TxtMessage.Text
oDoc.postdate = Date
Form1.StatusBar1.SimpleText = "Attaching Database " & Form1.TxtFilePath
Call oItem.EMBEDOBJECT(1454, "", Form1.TxtFilePath)
oDoc.visable = True
Form1.StatusBar1.SimpleText = "Sending Message"
oDoc.SEND False
exit_SendAttachment:
On Error Resume Next
Set oSess = Nothing
Set oDB = Nothing
Set oDoc = Nothing
Set oItem = Nothing
Form1.StatusBar1.SimpleText = "Done!"
Form1.MousePointer = 1
Exit Sub
err_handler:
If Err.Number = 7225 Then
MsgBox "File doesn't exist"
Else
MsgBox Err.Number & " " & Err.Description
End If
On Error GoTo exit_SendAttachment
Form1.MousePointer = 1
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.