Adapt a VB script to send Lotus Notes email in Msch.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Dave1

Adapt a VB script to send Lotus Notes email in Msch.

Post by Dave1 » Tue Sep 23, 2003 11:03 pm

Hi experts,
I've been searching left and right to find a way to do so. Yesterday, I found this script from VBCode.com so I thought the best way would be to post it here in hope that one of you would take a moment to to revise it for use in Scheduler. Note, it would be most helpful to be able to send to multiple people at once.
Thanks greatly.


'Task: Use this to send an email to somebody....

'Declarations
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA"
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As
Long
Private Const SW_SHOW = 5


'Code:
ShellExecute hwnd, "open", "mailto:[email protected]", vbNullString,
vbNullString, SW_SHOW

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Sep 24, 2003 6:50 am

Hi,

Um, all this script does is open your default email client with a new message to [email protected]. It has nothing to do with Lotus Notes! Oh, and, please do not confuse VB with VBScript. Your code will not work in Macro Scheduler.

If you just want to send an email why not use SMTPSendMail?

We don't use Lotus Notes so I am unable to test this, but a search on the net revealed that Lotus Notes does manifest an ActiveX interface and therefore can be scripted with VBScript. From what I can gather something like the following should work:

VBSTART

Sub SendNotesMail
Set nSession = CreateObject("Notes.NotesSession")
'Gets the current user's maildatabase
Set db = nSession.GETDATABASE("","")
Call db.OPENMAIL
Set doc = db.CREATEDOCUMENT
Call doc.REPLACEITEMVALU("SendTo", "DemoDolly/HBP/Hydro@Hydro")
Call doc.REPLACEITEMVALUE("Subject", "Mail sent from VBscript using Lotus Notes")
Call doc.REPLACEITEMVALUE("Body", "Does it work?")
Call doc.SEND(False)
End Sub

VBEND
VBRun>SendNotesMail

Please don't expect this to run without modification. You need to read the lotus notes documentation for it's ActiveX specification. I would also check out Usenet and so on. I found the following Notes forum which might be of help. Search for VBScript: http://www-10.lotus.com/ldd/46dom.nsf
MJT Net Support
[email protected]

dave1

Post by dave1 » Wed Sep 24, 2003 11:51 pm

Hi,
Thank you greatly to take the time explaining and helping.
I modified and tried the code several times at work today but always got the error message on the last line:

VBRun>SendNotesMail

According to the documentation of Lotus Notes, I should be able to set up smtp mail so I will try that again with the command SMTPSendMail.

Should I get it to work, I will post the result.

Thank you,

P.S. Anybody ever read Lotus Notes documentation? LOL, it may take a life time to learn the software.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Sep 25, 2003 7:46 am

Hi,

You don't say what the error message was. Please provide the error message so that we can try and help.
MJT Net Support
[email protected]

Dave1

Post by Dave1 » Thu Sep 25, 2003 2:08 pm

Hi Support,

The error message that I mentionned earlier was caused by the extra space after each line.

Then, changing a typo error from 'Call doc.REPLACEITEMVALU' to 'Call doc.REPLACEITEMVALUE', Lord and Behold, your script WORKS beautifully.

If Lotus Notes not yet opens, the script will ask for password.
When the script completes, it leaves Lotus Notes open.

Thanks, thanks, and thanks greatly.

tfloyd
Newbie
Posts: 5
Joined: Mon Aug 28, 2006 9:53 pm

Lotus Notes Attach a file

Post by tfloyd » Tue Aug 29, 2006 4:52 pm

Here are some modifications that will allow you to attach a PDF file.

I still can't get it to email to multiple recipents. Can anyone help with this?

VBSTART

Sub SendNotesMail
Set nSession = CreateObject("Notes.NotesSession")

Gets the current user's maildatabase
Set db = nSession.GETDATABASE("","")
Call db.OPENMAIL
Set doc = db.CREATEDOCUMENT



Call doc.REPLACEITEMVALUE("Subject", "Mail sent from VBscript using Lotus Notes")
Call doc.REPLACEITEMVALUE("Body", "This should work!")
Call doc.REPLACEITEMVALUE("SendTo", "me@nowhere")




sAttachment = "C:somefile.pdf"

Set AttachME = doc.CreateRichTextItem("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", sAttachment, "Attachment")


Call doc.SEND(False)
End Sub

VBEND
VBRun>SendNotesMail

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Lotus Notes Attach a file

Post by Marcus Tettmar » Tue Aug 29, 2006 4:58 pm

tfloyd wrote:I still can't get it to email to multiple recipents. Can anyone help with this?
Can't you just do:

Call doc.REPLACEITEMVALUE("SendTo", "me@nowhere,[email protected],[email protected],[email protected]")

But if you don't want recipients to see everyone elses emails then just loop it for the list of recipients so you get a new email for each recipient. Add the recipient address as a parm on the subroutine, so you'd call it with:

VBRun>SendNotesMail,[email protected]

Then you can loop through a list of recipients, something like:

..
Repeat>x
Let>x=x+1
VBRun>SendNotesMail,recips_%x%
Until>x=recips_count
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

tfloyd
Newbie
Posts: 5
Joined: Mon Aug 28, 2006 9:53 pm

Post by tfloyd » Tue Sep 05, 2006 2:03 pm

Lotus would not accept multiple emails in one line. I was finally able to send the attachment to multiple recipents with this.


VBSTART

Sub SendNotesMail
Set nSession = CreateObject("Notes.NotesSession")

Dim arrRecipients(5)

arrRecipients(0) = "[email protected]"
arrRecipients(1) = "[email protected]"
arrRecipients(2) = "[email protected]"
arrRecipients(3) = "[email protected]"
arrRecipients(4) = "[email protected]"
arrRecipients(5) = "[email protected]"

'Gets the current user's maildatabase
Set db = nSession.GETDATABASE("","")
Call db.OPENMAIL
Set doc = db.CREATEDOCUMENT


Call doc.REPLACEITEMVALUE("Subject", "Credit Notes for Month")
Call doc.REPLACEITEMVALUE("Body", "See attached PDF file")

sAttachment = "C:\attachereport.pdf"

Set AttachME = doc.CreateRichTextItem("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", sAttachment, "Attachment")

Call doc.SEND(False, arrRecipients)


End Sub

VBEND
VBRun>SendNotesMail

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Sep 05, 2006 2:10 pm

Ah, so it wanted an array. Excellent.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Sun Sep 10, 2006 7:42 am

tfloyd wrote:. . . .

Call doc.REPLACEITEMVALUE("Subject", "Credit Notes for Month")
Call doc.REPLACEITEMVALUE("Body", "See attached PDF file")

sAttachment = "C:\attachereport.pdf"

. . . .
VBEND
VBRun>SendNotesMail
Hi, thanks for the tips.
Wishfull thinking: How to use variable in sAttachment, and in Subject & Body.
I think that I have a work-around for the sAttachment (such as to change/write a file to send, prior to running the script), but no option for the latter two.

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Sep 10, 2006 8:16 am

Put the parameters in the subroutine:

Code: Select all

VBSTART

Sub SendNotesMail(strSubject, strBody, strAttachment)

	Set nSession = CreateObject("Notes.NotesSession")
	Dim arrRecipients(5)

	arrRecipients(0) = "[email protected]"
	arrRecipients(1) = "[email protected]"
	arrRecipients(2) = "[email protected]"
	arrRecipients(3) = "[email protected]"
	arrRecipients(4) = "[email protected]"
	arrRecipients(5) = "[email protected]"

	'Gets the current user's maildatabase
	Set db = nSession.GETDATABASE("","")
	Call db.OPENMAIL
	Set doc = db.CREATEDOCUMENT

	Call doc.REPLACEITEMVALUE("Subject", strSubject)
	Call doc.REPLACEITEMVALUE("Body", strBody)

	If strAttachment <> "" then
	   Set AttachME = doc.CreateRichTextItem("Attachment")
  	   Set EmbedObj = AttachME.EmbedObject(1454, "", strAttachment, "Attachment")
	end if

	Call doc.SEND(False, arrRecipients)

End Sub

VBEND
VBRun>SendNotesMail,Credit Notes for Month,See attached PDF file,C:\attachereport.pdf

Any time you want to pass variables into vbscript you do so by calling a Sub or Function using VBRun or VBEval:

VBSTART
Sub MySub(vara, varb)
...
End Sub
VBEND

VBRun>MySub,some value,another value

Let>A=Fred
Let>B=Sally
VBRun>MySub,%A%,%B%

etc
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mydave
Junior Coder
Posts: 39
Joined: Fri Jul 22, 2005 12:42 pm

Post by mydave » Sun Sep 10, 2006 9:53 am

Hello Marcus!
Do you ever sleep?
Thanks greatly. This is a big help.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts