Ick. (Though I'm in the same boat - I recently changed jobs from a company
that used Outlook to one that uses Lotus.)
I've never done it myself, but here is some *untested* code I found on this
NG.
Sub testSendMail()
Dim bOK As Boolean
bOK = sendNotesMail(Range("Subject"), Range("Attachment"),
Range("Recipient"), Range("BodyText"), Range("SaveIt"))
MsgBox "sent: " & CStr(bOK)
End Sub
Function sendNotesMail(Subject As String, attachment As String, recipient As
String, bodytext As String, SaveIt As Boolean) As Boolean
Dim Maildb As Object
Dim UserName As String
Dim MailDbName As String
Dim MailDoc As Object
Dim AttachME As Object
Dim session As Object
Dim EmbedObj As Object
On Error GoTo err_SendNotesMail
'Start a session to notes
Set session = 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 = session.UserName
MailDbName = Mid$(UserName, 4, 1) & Right$(UserName, (Len(UserName) -
InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = session.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 = recipient
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SaveMessageOnSend = SaveIt
'Set up the embedded object and attachment and attach it
If attachment <> "" And Dir(attachment) <> "" Then
Set AttachME = MailDoc.CreateRichTextItem("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", attachment, "Attachment")
'MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.Send 0, recipient
Maildb.Close
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing
sendNotesMail = True
end_SendNotesMail:
Exit Function
err_SendNotesMail:
Select Case Err.Number
Case 429:
MsgBox "Error: " & vbCrLf & Err.Description & vbCrLf & "Possible
cause:" & vbCrLf & "Lotus Notes not installed", vbCritical, "Error
whileinitializing LotusNotes"
Case Else:
MsgBox Err.Description & Err.Number, vbCritical, "Error Lotus Notes
Mail"
End Select
Resume end_SendNotesMail
End Function
Sub SendLotusNote()
' be sure to reference the Lotus Domino Objects, domobj.tlb
Dim objNotesSession As Object
Dim objNotesDatabase As Object
Dim objNotesDocument As Object
Dim objAttachment As Object
Dim objRichText As Object
Dim FullPath As String
Dim FileName As String
Dim Msg As String
Const EMBED_ATTACHMENT = 1454
Set objNotesSession = CreateObject("Notes.Notessession")
Set objNotesDatabase = objNotesSession.GETDATABASE("", "")
Call objNotesDatabase.OpenMail default mail database
If objNotesDatabase.IsOpen = False Then
MsgBox "Cannot connect to Lotus Notes."
Exit Sub
End If
Set objNotesDocument = objNotesDatabase.CreateDocument
Call objNotesDocument.ReplaceItemValue("Form", "Memo")
Do ' prompt user for file name and location
FullPath = Application.GetSaveAsFilename
Loop Until FullPath <> False
' save to new loc; Lotus only sends last-saved copy
ActiveWorkbook.SaveAs FullPath
FileName = ActiveWorkbook.Name
' assemble message
Set objRichText = objNotesDocument.CreateRichTextItem("Body")
Set objAttachment = objRichText.EmbedObject(EMBED_ATTACHMENT, "",
FullPath, FileName)
Msg = "Lotus Note sent from " & objNotesSession.CommonUserName
With objNotesDocument
.Subject = "Excel Lotus Note!"
.Body = Msg
.sendTo = "lotus.mailbox"
.SaveMessageOnSend = True ' save in Sent folder
.Send (False)
End With
Set objNotesSession = Nothing
Set objNotesDatabase = Nothing
Set objNotesDocument = Nothing
Set objAttachment = Nothing
Set objRichText = Nothing
MsgBox "Your Lotus Notes message was successfully sent"
ActiveWorkbook.Close
End Sub
Sub EMail()
'You will also need to reference 'Notes32.tlb' in your project.
Dim session As Object
Dim db As Object
Dim doc As Object
Set session = CreateObject("Notes.NotesSession")
Set db = session.GETDATABASE("Your Domino Server", "Your Mail Database")
Set doc = db.CreateDocument()
doc.Form = "Memo"
doc.Subject = "VB App Test " & Now()
doc.Body = "VB App Test. Sending Notes memos via VB"
doc.sendTo = "(e-mail address removed)"
Call doc.Send(False, "")
Set doc = Nothing
Set db = Nothing
Set session = Nothing
End Sub
Sub mailsend2()
Dim Data As Variant
Dim mailcount As Integer
Dim s As Object, db As Object, doc As Object
Data = Range("A1:B6").Value 'defines the source data in two cols on
active sheet
Set s = CreateObject("Notes.NotesSession")
Set db = s.GETDATABASE("", "mail\username.nsf")
Set doc = db.CreateDocument()
For mailcount = 1 To 6
doc.Form = "Memo"
doc.sendTo = Data(mailcount, 1)
doc.Subject = Data(Str(mailcount), 2)
doc.Body = "Rats Trousers" & " " & Data(Str(mailcount), 2)
Call doc.Send(False)
Next
Set s = Nothing
Set db = Nothing
Set doc = Nothing
End Sub