I have some code to email from Lotus notes. I found it a while ago on a
few web sites - there's two versions that I cobbled together to test but
the project fell through so neither version has ever been tested.
I hope it helps you out - if any of it does work it would be useful to know!
Watch for wrapping...
Public Function fcnSendLotusNotesMailV1(Subject As String, Attachment As
String, Recipient As Variant, BodyText As String, SaveIt As Boolean) As
String
Dim myErrs As String
'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 Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
On Error GoTo ErrorHandler
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Next line only works with 5.x and above. Replace password with
your password
'Session.Initialize ("password")
'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 or using above password you can use other
mailboxes.
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) -
InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Not Maildb.IsOpen Then
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
MailDoc.SendTo = Recipient
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, Recipient
ErrorHandler:
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
Err.Clear
End Function
Function fcnSendWithLotusV2(myPath As String, stTitle As String, stBody
As String, myRecipients As Variant) as boolean
Dim myErrs As String
Dim noSession As Object, noDatabase As Object, noDocument As Object
Dim obAttachment As Object, EmbedObject As Object
Dim stAttachment As String
Dim vaRecipient As Variant, vaMsg As Variant
Const EMBED_ATTACHMENT As Long = 1454
'Instantiate the Lotus Notes COM's Objects.
On Error GoTo ErrorHandler
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
'If Lotus Notes is not open then open the mail-part of it.
If noDatabase.IsOpen = False Then
noDatabase.OPENMAIL
End If
'Create the e-mail and the attachment.
Set noDocument = noDatabase.CreateDocument
Set obAttachment = noDocument.CreateRichTextItem("stAttachment")
Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", myPath)
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = myRecipients
.Subject = stTitle
.Body = stBody
.SaveMessageOnSend = True
End With
'Send the e-mail.
With noDocument
.PostedDate = Now()
.Send 0, myRecipients
End With
fcnSendWithLotusV2 = true
ErrorHandler:
'Clean Up
Set EmbedObject = Nothing
Set obAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
End Function