Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a Lotus Notes email with multiple addresses

Status
Not open for further replies.

Markkk01

IS-IT--Management
Jan 17, 2012
8
GB
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
 
Hi and thanks for the reply. I did try that but it still doesn't work.

I am using the variant (The one on the URL works fine but at the bottom it shows how to do multiple emails by changing and adding code, makes it look easy, if you know what you are doing)on the following URL but it doesn't seem to want to work. Either that or I have done something wrong. But according to the URL I think I have done the changes correctly. Any more ideas ?

 

Did you try to send an e-mail to just one person? Something like:
Code:
...
Dim recip As String
recip = "user@something.com"
...
If so, did it work OK?

Have fun.

---- Andy
 
Hi HughLerwill, thanks for the reply. I have now had a look at the URL's but I think there would be too much to change and as I'm not that confident in doing the work.

Hi Andrzejek, I did try to send to just 1 person but I still get the same error 'Expected End Of Statement' for the Dim recipient AS String !

What I have now is this set for 1 person for testing:

'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 Send File", CurrentDirectory & RNLIFilename, "Regards," & VbCrLf & "Mark", True)
Sub SendNotesMail(Subject, Attachment, BodyText, SaveIt)
'Set up the objects required for Automation into lotus notes
Dim Maildb 'The mail database
Dim UserName 'The current users notes name
Dim MailDbName 'THe current users notes mail database name
Dim MailDoc 'The mail document itself
Dim AttachME 'The attachment richtextfile object
Dim Session 'The notes session
Dim EmbedObj 'The embedded object (Attachment)
Dim recipients As String
recipients = "person@emailaddress.co.uk"
'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)
'Set Maildb = Session.GETDATABASE("", "mail.box")
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 = recipients
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, recipients
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
 
Your code isn't VBA but VBS.
Replace this:
Dim recipients As String
with this:
Dim recipients

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV, yep that worked !

Can I add more email addresses to the recipients = "", as I need to send it to 4 people ?
 
Hi, thanks for the help but how do I sort it for multiple email addresses ? I tried to change it so that it had , "email@address", "email@address" but that doesn't work. I also tried the following:
Dim recipients ()
recipients(1) = email@address.co.uk
recipients(2) = email@address.co.uk

But that doesn't work either. So, I'm still stuck on getting it to work with multiple emails !

Any help again would be great.
 
Try;

Dim recipients(3)

recipients(0) = email@address0.co.uk
recipients(1) = email@address1.co.uk
recipients(2) = email@address2.co.uk
recipients(3) = email@address3.co.uk
 
Hi, thanks for the reply.

I have just tried the above and it now goes past that and now stops at the following:

MailDoc.sendto = recipients

with the message "This array is fixed or temporarily locked: 'MailDoc.sendto"

Nearly there, any ideas ?
 
Another variation;

dim a()
redim a(3)

recipients(0) = email@address0.co.uk
recipients(1) = email@address1.co.uk
recipients(2) = email@address2.co.uk
recipients(3) = email@address3.co.uk
 
Hi HughLerwill, I have now tried both ways and I still get the error "This array is fixed or temporarily locked: 'MailDoc.sendto
 
And this ?
Dim recipients
recipients = Array("email@address0.co.uk", "email@address1.co.uk", "email@address2.co.uk", "email@address3.co.uk")


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV, perfect, worked like a charm ! Exactly what I needed.

Thanks to everyone who helped me through this, all been very helpful !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top