I want to send a mail with a vbscript without opening Lotus Notes UI. I managed to write a script that allows to send email with attachments and everything works fine. However the application is launched when I run the macro and I want it to work silenty (without launching the application).
Here is my code:
Dim noSession As Object
Dim noDatabase As Object
Dim noDocument As Object
Dim paths() As String
'Instantiate the Lotus Notes COM's Objects.
Set MailSession = CreateObject("Notes.NotesSession")
Set MailDatabase = MailSession.GetDatabase("", "")
'If Lotus Notes is not open then open the mail-part of it.
If MailDatabase.IsOpen = False Then MailDatabase.OPENMAIL
'Create the list of recipients.
vaRecipients = VBA.Array(EmailTo)
vaCCRecipients = VBA.Array(EmailCC)
vaBCCRecipients = VBA.Array(EmailBCC)
Set MailDoc = MailDatabase.CreateDocument
MailDoc.Form = "Memo"
MailDoc.sendTo = vaRecipients
MailDoc.CopyTo = vaCCRecipients
MailDoc.BlindCopyTo = vaBCCRecipients
MailDoc.Subject = Subject
MailDoc.Body = Body
MailDoc.SAVEMESSAGEONSEND = True
MailDoc.ReplyTo = Sender
MailDoc.SMTPOriginator = Sender
MailDoc.Sender = Sender
MailDoc.principal = Sender
MailDoc.inetprincipal = Sender
MailDoc.from = Sender
MailDoc.inetfrom = Sender
MailDoc.displayfrom = Sender
paths = Split(AttachmentPaths, ";")
Dim richTextItem As Object
Dim AttachmentPath As String
For i = LBound(paths()) To UBound(paths())
AttachmentPath = paths(i)
Set richTextItem = MailDoc.CreateRichTextItem("Attachment" & i)
Call richTextItem.EmbedObject(1454, "", AttachmentPath)
Next i
MailDoc.Send 0, vaRecipients
'Release objects from memory.
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
MsgBox "The e-mail has successfully been created and distributed", vbInformation
The problem is that Lotus notes UI is launched everytime I run the macro because of this line:
If MailDatabase.IsOpen = False Then MailDatabase.OPENMAIL