Public Sub Send_Lotus_Notes_Emails2()
'References: Lotus Domino Objects
Dim NSession As Domino.NotesSession
Dim NMailDb As Domino.NotesDatabase
Dim NDocument As Domino.NotesDocument
Dim NRTItemBody As Domino.NotesRichTextItem
Dim dataSheet As Worksheet
Dim lastRow As Long, r As Long
Dim FromName As String, FromEmail As String
Set dataSheet = ThisWorkbook.Worksheets("Sheet1")
FromName = "FirstName Surname" 'CHANGE THIS
FromEmail = "email@address.com" 'CHANGE THIS
'Start a Notes session using Lotus Domino Objects (COM classes)
Set NSession = New Domino.NotesSession 'COM, early binding
'Set NSession = CreateObject("Lotus.NotesSession") 'COM, late binding
'Get default mail database
With NSession
.Initialize "" 'supported in COM only
.ConvertMime = False 'do not convert MIME to rich text
Set NMailDb = .GetDatabase(.GetEnvironmentString("MailServer", True), .GetEnvironmentString("MailFile", True))
If Not NMailDb.IsOpen Then NMailDb.Open
End With
lastRow = dataSheet.Cells(Rows.Count, "A").End(xlUp).row
For r = 2 To lastRow
Set NDocument = NMailDb.CreateDocument
With NDocument
.ReplaceItemValue "Form", "Memo"
.ReplaceItemValue "Subject", "This is the email subject"
Debug.Print dataSheet.Cells(r, "C").Value, .GetItemValue("Subject")(0)
.ReplaceItemValue "SendTo", dataSheet.Cells(r, "C").Value
'Set sender name and email address
.ReplaceItemValue "From", FromName & " <" & FromEmail & ">" 'name and email address
.ReplaceItemValue "Principal", FromName & " <" & FromEmail & "@NotesDomain>" 'name and email address
'.ReplaceItemValue "Principal", FromEmail & "@NotesDomain" 'just email address
'Create the email body
Set NRTItemBody = .CreateRichTextItem("Body")
With NRTItemBody
.AppendText "Start of the email body text."
.AddNewLine 2
.AppendText "To: " & dataSheet.Cells(r, "A").Value & " " & dataSheet.Cells(r, "B").Value
.AddNewLine
.AppendText "Phone Number: " & dataSheet.Cells(r, "E")
.AddNewLine 2
.AppendText "End of the email body text." & vbCrLf
'Attach the file if it exists
If Dir(dataSheet.Cells(r, "D").Value) <> "" Then
.EmbedObject EMBED_ATTACHMENT, "", dataSheet.Cells(r, "D").Value, "Attachment"
End If
End With
.SaveMessageOnSend = True
.Send False
End With
Next
Set NRTItemBody = Nothing
Set NDocument = Nothing
Set NMailDb = Nothing
Set NSession = Nothing
End Sub