Hi, I am very new to VB and am I trying to get some code working that will (from a CMD file) create an email in Lotus Notes with 4 addresses and 1 attachment. I have found some code for this and I tried to get it working with what I need but I am hitting a wall, as I am getting an error and not sure what to do.
So, it would be a great learning curve for me to have some help to figure it out. The error I am getting is with the As Variant, see below, please tell me where I am going wrong:
' Name : SendNotesMail
' Function : Send a Mail using Lotus Notes
' Author : Alain Aucordier (alain.aucordier@socgen.com)
' Created : 19/04/2001. Copyright 2001@ArtOfNet
' Modified : 2012 Mark Knight [RNLIMAIL.VBS]
'Set up paths, files and e-mail addresses
Set oShell = CreateObject( "WScript.Shell" )
CurrentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(Len(WScript.ScriptName)))
RNLIFilename=oShell.ExpandEnvironmentStrings("%rnlifilename%")
Call SendNotesMail("RNLI Feed File", CurrentDirectory & RNLIFilename, "Regards," & VbCrLf & "Mark", True)
Public Sub SendNotesMail(Subject, Attachment, BodyText, SaveIt)
'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)
Dim recip(3) As Variant 'Send to Multiple addresses
recip(0) = "user@something.com"
recip(1) = "user@something.com"
recip(2) = "user@something.com"
recip(3) = "user@something.com"
'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 = "mknight.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 = recip
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
'Send the document
MailDoc.SEND 0, recip
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
Any help would be grateful
Regards
Mark
So, it would be a great learning curve for me to have some help to figure it out. The error I am getting is with the As Variant, see below, please tell me where I am going wrong:
' Name : SendNotesMail
' Function : Send a Mail using Lotus Notes
' Author : Alain Aucordier (alain.aucordier@socgen.com)
' Created : 19/04/2001. Copyright 2001@ArtOfNet
' Modified : 2012 Mark Knight [RNLIMAIL.VBS]
'Set up paths, files and e-mail addresses
Set oShell = CreateObject( "WScript.Shell" )
CurrentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(Len(WScript.ScriptName)))
RNLIFilename=oShell.ExpandEnvironmentStrings("%rnlifilename%")
Call SendNotesMail("RNLI Feed File", CurrentDirectory & RNLIFilename, "Regards," & VbCrLf & "Mark", True)
Public Sub SendNotesMail(Subject, Attachment, BodyText, SaveIt)
'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)
Dim recip(3) As Variant 'Send to Multiple addresses
recip(0) = "user@something.com"
recip(1) = "user@something.com"
recip(2) = "user@something.com"
recip(3) = "user@something.com"
'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 = "mknight.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 = recip
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
'Send the document
MailDoc.SEND 0, recip
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
Any help would be grateful
Regards
Mark