Baanboard.com

Baanboard.com (http://www.baanboard.com/baanboard/index.php)
-   Code & Utilities (http://www.baanboard.com/baanboard/forumdisplay.php?f=33)
-   -   CODE: How to use MS OUTLOOK? (http://www.baanboard.com/baanboard/showthread.php?t=5772)

carice 10th July 2002 12:03

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

NPRao 10th July 2002 21:10

Hi Carise,

That was very good code. I was wondering if you considered using the BaaN Tools CMF options: http://www.baanboard.com/programmers_manual_baanerp_help_emessage_connector_cmf_createrecipient

carice 11th July 2002 00:50

yep
 
That's right ; i have considered cmf but it wasn't so flexible like mine. You can do whatever you wanted with your message in my code.
You don't have to work with a session and a form. In our company the responsible of reminders , ... will have automatically all the reminders in outlook in a special folder where he can decided to mail it or not (Just 1 example what you can do with this code).

I'm happy that you like the code although i think improvements can be done.

tnzabo 31st January 2008 20:03

old thread revived
 
Hi - this code you have posted here...does this simply allow you to use a Baan session as an email session - bypassing, sort of, Outlook? How does this work if I have a session in a job that runs with no user intervention and will email the report to a user?

Mikkann 18th May 2011 16:33

Very qood question - does anyone knows the solution?

bilmaa 12th July 2012 12:09

you can use other things
 
for example Blat utility, realy very useful utility.

teste.


All times are GMT +2. The time now is 21:33.


vB.Sponsors
©2001-2017 - Baanboard.com - Baanforums.com