Sunday, December 15, 2013

Macro - Send mail using lotus notes

Sub SendMail()
Dim myRow As Integer
Dim myCol As Integer
Dim myTemplate As String
Dim mySession As Domino.NotesSession
Dim notesDB As Domino.NotesDatabase
Dim notesDoc As Domino.NotesDocument
Dim body As NotesRichTextItem
Dim d(1 To 1000) As Variant
Dim month As Variant

Set mySession = New Domino.NotesSession
mySession.Initialize
Set notesDB = mySession.GetDatabase("Mail Database", "mailUser.nsf")

If (Not notesDB.IsOpen) Then
            notesDB.Open
End If

Set notesDoc = notesDB.CreateDocument


With notesDoc
            .AppendItemValue "Form", "memo"
            .AppendItemValue "From", "Name"
            .AppendItemValue "Principal", "Main name"
            .AppendItemValue "SendTo", "mail@mail.com"
            .AppendItemValue "Subject", "Subject "

End With

Set body = notesDoc.CreateRichTextItem("Body")
Call body.AppendText("Hi Everybody,")
Call body.AddNewLine(2)
Call body.AppendText("Add more lines :")
Call body.AddNewLine(2)

For n = 1 To Count
            Call body.AppendText(d(n))
Call body.AddNewLine
Next n

Call body.AddNewLine(2)
Call body.AppendText("Thanks & Regards,")
Call body.AddNewLine(1)
Call body.AppendText("Sender")
Call notesDoc.Send(False)
MsgBox "Mail sent successfully. Boss!!!", vbOKOnly, "Mail Sent"

' release memory
Set notesDoc = Nothing
Set notesDB = Nothing
Set mySession = Nothing
End Sub