View Single Post
  #1  
Old 10th July 2002, 12:03
carice's Avatar
carice carice is offline
Member
 
Join Date: Mar 2002
Location: Belgium
Posts: 38
carice is on a distinguished road
Baan: BaanIV; BaanV (5.0;5.1;5.2) - DB: BISAM; ORACLE - OS: WINNT; UNIX
Post How to use MS OUTLOOK

In baan you create a session with a few formfields (you can start with from; to ; subject and body).
In a later stadium you can use more fields like cc, attachment, ...
Code:
|******************************************************************************
|* Send Outlook Mail
|* filip demeulemeester
|* 06-03-02 [09:13]
|*
|* Copyright 2002 by Demeulemeester Filip
|* You can contact me at <a href="mailto:flaip@hotmail.com">flaip@hotmail.com</a>
|* All Rights Reserved 
|*
|* Permission to use, copy, modify, and distribute this software and its documentation for any purpose 
|* and without fee is hereby granted, provided that the above copyright notice appear in all copies 
|* and that both that copyright notice and this permission notice appear in supporting documentation. 
|*
|* Demeulemeester Filip and Baanboard.com DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 
|* Demeulemeester Filip nor Baanboard.com BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
|* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
|* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
|*
|******************************************************************************
|* Script Type: 4
|******************************************************************************
declaration:
|* form fields
extern domain tcmcs.s256	frmFrom, varfrom
extern domain tcmcs.s256	frmTo, varto
extern domain tcmcs.s256	frmSubject, varsubject
extern domain tcmcs.s256	frmBody, varbody
extern domain tcmcs.s256	frmCat, varcat
extern domain tcmcs.s256	frmBCC, varbcc
extern domain tcmcs.s256	frmCC, varcc
extern domain tcmcs.s256	frmAtt, varatt
extern domain tcmcs.s256	frmAction, varaction

functions:
function extern send_email()
{
	long   ret
	string commandline(2560)
	
	varfrom 	= """" & frmFrom & """"
	varto  	= """" & frmTo & """"
	varsubject 	= """" & frmSubject & """"
	varbody 	= """" & frmBody & """"
	varcat 	= """test"""
	varbcc 	= """bccfide"""
	varcc 	= """ccfide"""
	varatt 	= """"""
	varaction 	= """move"""	| or copy or save or send cfr script below
	
	commandline = "outlook.vbs " & varfrom & " " & varto & " " & varsubject & " " & varbody & " " & varcat & " " & varbcc & " " & varcc & " " & varatt & " " & varaction
	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 system-directory:
Code:
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
In this example he will put draft in a new created folder under the outboxfolder.
When you can make improvements ; please contact me
Reply With Quote