TITLE:Sending Email from MultiValue Hosts

ISSUE:Multi-value Solutions Jun '98

AUTHOR:Nathan Rector

COMPANY:Natec Systems

EMAIL:nater@northcoast.com

HTTP:www.northcoast.com/~nater/

There are many internet email programs, but few that will work with your MultiValue database. The ones designed for the MultiValue databases consist native systems like Pic-Lan IP, or Windows and UNIX host email programs. Both these kind of programs have their own advantages and disadvantages.

For the purpose of this article, I’m going to talk about using Windows 95’s built in messaging system to send internet email. If you are working with a MultiValue system that currently doesn’t have the ability to access the Windows environment, there are several third-party products that will give this access: Pic-Lan for native platforms, and WinLink for most any other.

The program I’ve included is a Visual Basic program. (Figure 1) It only uses the basic functions of Windows Messaging and requires the MultiValue host to do the controlling of how to process the email. Also included is a sample routine that transfers the email data from the MultiValue host to Windows using Pic-Lan. (Figure 2)

Once you are able to transfer the email information from the MultiValue hosts to Windows you have to setup the Windows Messaging system. This is also known as the InBox on the Windows Desktop. If you already use the InBox on your Windows Desktop, then there is no additional setup needed. All that needs to be done to this program is have the Profile Name changed to your existing Profile Name.

If you have never used the InBox on Windows, then you can setup your new profile by going to "Control Panel" and "Mail and Fax". Click on the "Show Profiles" button and create your Profile. If you have an original version of Windows 95, you may have to upgrade the Windows Messaging Subsystem. You can find the upgrade file at http://www.microsoft.com/. If you have OutLook 97 or Office 97 loaded on your system, it is likely you are already using the most current files. However, if this Visual Basic program does not work, then you need to upgrade the Windows Messaging Subsystem.

This program looks in the directory C:\mvEmail for any text file that has the extension of ‘.ems’. The file format is:

To: = the address you wish to send the email to. Each ‘To:’ can only have one address, but you can have as many as you want.

CC: = the address you wish to send a carbon copy of the email to. Each ‘CC:’ can only have one address, but you can have as many ‘CC:’ as you want.

BCC: = the address you wish to send a blind copy of the email to. Each ‘BCC:’ can only have one address, but you can have as many ‘BCC:’ as you want.

SUBJECT: = is the subject of the email

Any other text that don’t have these keywords will be part of the body of your email.

Example:

100.ems

to:home@northcoast.com

cc:solution@northcoast.com

bcc:nater@northcoast.com

subject:testing new message system

Testing new email program.

The program checks for these files, and as each one is processed, then file is deleted to keep it from being processed again. Once the email has been read and processed, it is sent.

If you are using WinLink or a MultiValue host that has Visual Basic hooks, the subroutine that read the item from the file and processes it can be easily modified to read directly from the MultiValue host.

The code in this article will not run by itself. The code supplied is a module that must be called from an existing or new program. The easiest way to use these routines is to create a VB form with a timer control on it. In the timer control place the following code:

Sub Timer1_Timer()

Call SendMessage

End Sub

If you use Microsoft Exchange for in-office email, this program can also be used to send that type of email as well. The only difference is the format of ‘To:’ addresses and making sure that Microsoft Mail is enabled on your Profile Name as well as Internet Mail.

The same goes for sending Faxes. One word of caution, Windows 98 currently does not have the generic fax program that was supplied with Windows 95. This may have changed since I last looked, but if you plan on upgrading, you will need to keep this in mind.

Next month I will include the code that you can add to this program that will process any received internet email. However, if you want to take a look of a sample visual basic program ahead of time, a full working program and project can be downloaded from this article at http://www.northcoast.com/~nater/solutions.

 

' Created By Nathan Rector

' Natec Systems

'

' these routines are used to send Email messages

Private Function ReadRecord(RecordName As String, ErrMsg As String) As Boolean

Dim MapiSession As Object

Dim MapiMessage As Object

Dim MapiRecipient As Object

Dim errObj As Long

Dim FileHandle As Integer

Dim Line As String

Dim LineType As String

Dim LineData As String

Dim I As Integer

' this routine is used to read a dos file and process it

' into an email message

ReadRecord = True

On Error GoTo MAPITrap

' opens file to process

FileHandle = FreeFile

Open RecordName For Input As FileHandle

' creates the Mapi Session

Set MapiSession = CreateObject("Mapi.Session")

' Log on to the session. If the ProfileName argument is omitted,

' Microsoft Exchange prompts you for the profile to use. If the

' profile name is incorrect, you will receive a runtime error.

MapiSession.Logon ProfileName:=""

' Add a message to the Outbox.

Set MapiMessage = MapiSession.Outbox.Messages.Add

' Reads the Record and extracts information

Do Until EOF(FileHandle)

Line Input #FileHandle, Line

' finds the LineType and the LineData

Pos = InStr(1, Line, ":")

If Pos > 0 Then

LineType = Mid(Line, 1, Pos - 1)

LineData = Mid(Line, Pos + 1)

Else

LineType = ""

LineData = Line

End If

' updates the message

' Add the recipients of the message. Note, each recipient must be

' added separately to the Recipients collection of the Message

' object.

Select Case UCase(LineType)

Case "TO"

Set MapiRecipient = MapiMessage.Recipients.Add

MapiRecipient.Name = LineData

MapiRecipient.Type = mapiTo

Case "CC"

Set MapiRecipient = MapiMessage.Recipients.Add

MapiRecipient.Name = LineData

MapiRecipient.Type = mapiCc

Case "BCC"

Set MapiRecipient = MapiMessage.Recipients.Add

MapiRecipient.Name = LineData

MapiRecipient.Type = mapiBcc

Case "SUBJECT"

MapiMessage.Subject = LineData

Case Else

MapiMessage.Text = MapiMessage.Text & Line & vbCrLf

End Select

Loop

' Resolve each recipient's e-mail name.

For I = 0 To MapiMessage.Recipients.Count - 1

MapiMessage.Recipients(I).Resolve showdialog:=False

Next

' the ShowDialog argument is False to send the

' message without viewing it in Microsoft Exchange.

MapiMessage.Send showdialog:=False

'closes MAPI session.

Set MapiSession = Nothing

' Clear the object variable.

MAPIExit:

On Error Resume Next

Close FileHandle ' closes the file

Exit Function

MAPITrap:

SendEmailMessage = False

errObj = Err - vbObjectError ' Strip out the OLE automation error.

Select Case errObj

Case 275 ' User cancelled sending of message.

Resume MAPIExit

Case Else

ErrMsg = "Error " & errObj & " was returned. " & Err.Description

Resume MAPIExit

End Select

End Function

 

Public Sub SendMessage()

Dim DirList As String

Dim ErrMsg As String

Dim EmailPath As String

' this routine will process each email message it find

' in the Directory c:\mvEmail

On Error Resume Next

EmailPath = "C:\mvEmail\"

DirList = Dir(EmailPath & "*.ems")

Do While DirList <> ""

' send the email message

If ReadRecord(EmailPath & DirList, ErrMsg) Then

' message was sent, Delete

Kill EmailPath & DirList

Else

' Error when sending.

End If

' gets the next item in the dir

DirList = Dir

Loop

End Sub

 

 

 

SUBROUTINE TEST

*

* this program is used to send an email message to the Windows Email Program

*

EMAIL.ITEM = ""

EMAIL.ITEM<-1> = "TO:nater@northcoast.com"

EMAIL.ITEM<-1> = "SUBJECT:Testing new email program"

EMAIL.ITEM<-1> = "Testing new email program body."

EMAIL.ITEM<-1> = "LINE 2"

*

CALL PLSUB.INIT ;* as per manual

CALL PLSUB.DSG("OPEN CONNECTION",PLCB.HANDLE,"DSG","","","","","",ERR)

IF ERR # "" THEN GOTO 900

*

RW.MODE = "W" ; SH.MODE = "W"

CALL PLSUB.DSG("DOS OPEN",PLCB.HANDLE,"C:\mvEmail\100.EMS",RW.MODE,SH.MODE,"",FILE.HANDLE,"",ERR)

IF ERR # "" THEN GOTO 900

IF FILE.HANDLE = "" THEN GOTO 900

*

CALL PLSUB.DSG("DOS WRITE",PLCB.HANDLE,FILE.HANDLE,"0","A",EMAIL.ITEM,RESULT,"",ERR)

IF ERR # "" THEN GOTO 900

*

CALL PLSUB.DSG("DOS CLOSE",PLCB.HANDLE,FILE.HANDLE,"","","","","",ERR)

900*

CALL PLSUB.DSG("CLOSE CONNECTION",PLCB.HANDLE,"","","","","","",ERR)

*

CALL PLSUB.INIT ;* as per manual

END