Adapt a VB script to send Lotus Notes email in Msch.
Moderators: Dorian (MJT support), JRL
Adapt a VB script to send Lotus Notes email in Msch.
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
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
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
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]
[email protected]
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.
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.
Hi,
You don't say what the error message was. Please provide the error message so that we can try and help.
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]
[email protected]
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.
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.
Lotus Notes Attach a file
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Lotus Notes Attach a file
Can't you just do:tfloyd wrote:I still can't get it to email to multiple recipents. Can anyone help with this?
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Hi, thanks for the tips.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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Put the parameters in the subroutine:
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
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?