carice
6th March 2002, 11:54
I have written a dll in VB that sends an email with outlook. In this dll there is a function that can be called with different arguments. Is it possible now to call in a baan session this VB dll-function with it's arguments?
Youp2001
6th March 2002, 12:25
Why trying to send an email using a VB DLL. You can find multiple threads here about how to send an email from you Baan system.
If you want to use Outlook, why don't you use functions server2client(...) and app_start(...).
Regards,
Youp
mark_h
6th March 2002, 14:28
I agree with Youp. Plenty of threads on how send email from Baan. But you could take that DLL and make it an executable routine and then call that from Baan using the app_start. I am not sure how you would directly call a VB dll or even if you could.
Mark
carice
7th March 2002, 10:22
Thanks to all;
I have make the following solution. The problem is that you can write VB-programs that runs baan-functions or read baan tables; but i was searching for a way to call in my Baan-program a VB-DLL and give some arguments with it.(Think to the possibilities if you can do that) As far as i know you can use app_start but you cannot give arguments with it.
In a first stadium i will make a baansessions where you can give in the from, to, subject and body. In a later stadium i will write it in a device conversion program so that you really can mail whatever you want from baan. This functionality is also useable for other programs. There can be a lot of improvements, i know but it's a start. With the following code, a email is send from baan and it's in baan where you specify the from, to, subject and body (to start with). The program will create a email and put it into a new folder that he creates under the outbox folder.
Here my first solution (any reply or suggestions are welcome)
In baan there is a session
with four formfields (frmFrom; frmTo; frmSubject; frmBody)
the hardcoded fields will also be formfields in a later stadium
|***************************************************
|* cobte0106 0 VRC B50M b ba02
|* Send Outlook Mail
|* 06-03-02 [09:13]
|***************************************************
|* Script Type: 4
|***************************************************
declaration:
extern domain tcmcs.s256 frmFrom
extern domain tcmcs.s256 frmTo
extern domain tcmcs.s256 frmSubject
extern domain tcmcs.s256 frmBody
extern domain tcmcs.s256 frmCat
extern domain tcmcs.s256 frmBCC
extern domain tcmcs.s256 frmCC
extern domain tcmcs.s256 frmAtt
extern domain tcmcs.s256 frmAction
functions:
function extern send_email()
{
long ret
string commandline(2560)
frmFrom = """" & frmFrom & """" |formfield
frmTo = """" & frmTo & """" |formfield
frmSubject = """" & frmSubject & """" |formfield
frmBody = """" & frmBody & """" |formfield
frmCat = """test""" |hardcoded
frmBCC = """bcctest""" |hardcoded
frmCC = """cctest""" |hardcoded
frmAtt = """""" |hardcoded
frmAction = """move""" |hardcoded
commandline = "outlook.vbs " & frmFrom & " " & frmTo & _
" " & frmSubject & " " & frmBody & _
" " & frmCat & " " & frmBCC & _
" " & frmCC & " " & frmAtt & _
" " & frmAction
ret = app_start(commandline,"","","","")
}
There is also a vbs-script that is called outlook.vbs (this is just a textfile)
To use this vbs-script the path must be specified or the script must be in the windows system-directory(cfr PATH):
Dim obj
Dim nCount
Dim i
dim vfrom, vto, vsubject, vbody, vcat, vbcc, vcc, vatt, vaction
nCount = WScript.Arguments.Count
wscript.echo ncount
vfrom = cstr(Wscript.arguments(0))
vto = cstr(Wscript.arguments(1))
vsubject = cstr(Wscript.arguments(2))
vbody = cstr(Wscript.arguments(3))
vcat = cstr(Wscript.arguments(4))
vbcc = cstr(Wscript.arguments(5))
vcc = cstr(Wscript.arguments(6))
vatt = cstr(Wscript.arguments(7))
vaction = cstr(Wscript.arguments(8))
set obj = CreateObject("VBBAAN.BAANVB")
i = obj.sendBaanEmail(cstr(vfrom), cstr(vto), cstr(vsubject), _
cstr(vbody), cstr(vcat), cstr(vbcc), cstr(vcc), _
cstr(vatt), cstr(vaction))
set obj = Nothing
Last but not least there is a VB-script(activeX-dll) that process the mail:
Option Explicit
Private mOutlookApp As Outlook.Application
Private mNameSpace As Outlook.NameSpace
Private mOutbox As Outlook.MAPIFolder
Private mBaanOutbox As Outlook.MAPIFolder
Private mItem As Outlook.MailItem
Private bOK As Boolean
Private i As Integer
Private pRecip As Recipient
Private pAttachments As Attachments
Public Function SendBaanEmail(vFrom As String, vTo As String, _
vSubject As String, vBody As String, vCat As String, _
vBCC As String, vCC As String, vAtt As String, _
vAction As String) As Boolean
On Error GoTo auExit
SendBaanEmail = False
If GetOutlook() Then
If CreateFolder() Then
'Create Mail
Set mItem = mOutlookApp.CreateItem(olMailItem)
Set pRecip = mItem.Recipients.Add(vTo)
mItem.SentOnBehalfOfName = vFrom
mItem.Subject = vSubject
mItem.Body = vBody
mItem.Categories = vCat
mItem.BCC = vBCC
mItem.CC = vCC
'Add attachment
'Set pAttachments = mItem.Attachments
'pAttachments.Add vAtt, olByValue
Select Case vAction
Case "move"
mItem.Move mBaanOutbox
Case "copy"
mItem.Copy 'outbox
Case "save"
mItem.Save 'draft
Case "send"
mItem.Send 'inbox
End Select
Else
MsgBox "Failed to create baan folders"
End If
End If
Set mItem = Nothing
Set mOutbox = Nothing
Set mBaanOutbox = Nothing
Set mNameSpace = Nothing
Set mOutlookApp = Nothing
Exit Function
auExit:
MsgBox Err.Description
End Function
Function GetOutlook() As Boolean
On Error Resume Next
GetOutlook = False
Set mOutlookApp = New Outlook.Application
Set mNameSpace = mOutlookApp.GetNamespace("MAPI")
If Err Then
MsgBox "Failed to open oulook", vbCritical _
& vbCrLf & "Error: " & Err.Number & " " & Err.Description
Exit Function
End If
GetOutlook = True
End Function
Function CreateFolder()
On Error Resume Next
CreateFolder = False
Err.Clear
'open outbox folder
Set mOutbox = mNameSpace.GetDefaultFolder(olFolderOutbox)
'open or create baanoutbox folder
i = 1
bOK = False
While i <= mOutbox.Folders.Count
If mOutbox.Folders.Item(i).Name = "Outbox Baan" Then
bOK = True
Set mBaanOutbox = mOutbox.Folders("Outbox Baan")
End If
i = i + 1
Wend
If Not bOK Then
Set mBaanOutbox = mOutbox.Folders.Add("Outbox Baan", olFolderInbox)
End If
If Err.Number = 0 Then
CreateFolder = True
End If
End Function
alejandro
7th March 2002, 16:00
string commandline(512)
long ret,ret2
commandline ="file.exe param1;param2;param3"
ret = exec_dll_function("ottdllbw","app_start",ret2,strip$(commandline),"","","","")
In VB you use :
params=Command()
params will be a string with this value: param1;param2;param3
Then get the different parameters 1, 2 or 3 etc... with a function looking for the separator, in this case ; or any other separator you want to define (|, f.e.)
I`ve tested and used it.
file.exe is just an example.