MAPI is the acronym for Message Application Program Interface.  All I've tested it with is the interface to Outlook, Outlook Express & Netscape, but I understand that most Object Oriented email clients comply with the MAPI standard so the vocabulary for this example should apply to your desktop as well.

 

The PowerBuilder MAPI functions engage the 'default MAPI client' on your desktop.  When your script connects to the MAPI client you'll be prompted for your password if needed, otherwise the function call is almost instant on a quick processor or will take a few seconds on a '486

 

This example adds an Email button to our familiar button panel:

panelwithmail.jpg (22475 bytes)

The script for the Clicked event of cb_email launches a window which lets the User enter an email message in a multiline edit box and send it to the email addresses of Entities clicked in the grid below it:

dogmail2.jpg (63786 bytes)

The Window's name is w_emailer.  It contains: a multi line edit control, mle_messagetext;   dwc_emaillookup; dw_emaillookup; st_helper; and cb_close.

 

All that you'll need to do to send your Catalogs, Journal Vouchers, Purchase Orders, and Invoices via email is add MAPI functions in the right places of a script that looks like the one in SQL --> ASCII

There are numerous properties and functions for mailsession & mailmessage objects that will apply for 'real' situations.  Use PB Help on-line and check out mailSession & mailMessage thoroughly as you get into this topic.

 

Here are the scripts for these objects. 

 

There are a few 'hidden' pieces:

MessageToSend is an Instance Variable declared by getting to the Script pane for w_emailer & pulling down the Declare pane from the DropDown on the left.  Instance variables defined for an object are available by name from all the 'children' controls of the object.

dw_emaillookup is a DataWindow placed in dwc_emaillookup, defined as a grid, and called without any Retrieval Arguments.  

 

Following is intro vocabulary for sending email with MAPI.  The details about these new script elements may be found in PowerBuilder's Help.  

 

MailSession, mailMessage, and mailRecipient are three data types that make handling MAPI easy.  MailRecipient, for example, handles the email address & text name for the recipient structure of email.  mailMessage handles text and attachments for the message structure of email

ThisMailSession = CREATE mailsession creates a mailsession Object for us.

The next few lines log the mail session on to your MAPI and compare the results of the mailLogon function call to MailReturnSuccess!:

if ThisMailSession.mailLogon(MailNewSession!) <> mailReturnSuccess! then
          messagebox("Error logging onto mail session","This logon &
               attempt failed for the reason stated by the MAPI client. Please &
                  fix it and try again...")
          close(parent)
 end if

The next sequence loads appropriate properties with appropriate data types, dispatches the email, and destroys the mailsession object.  

Note that ThisMailMessage is a data structure which contains properties of internet mail: Recipient, Subject, and NoteText.

Note that mailSend is a method of ThisMailSession, so is mailLogoff.

ThisMailRecipient.Name = EmailAddress
ThisMailMessage.Recipient[1] = ThisMailRecipient
ThisMailMessage.Subject = "!*!*Testing from 9009*!*!"
ThisMailMessage.NoteText = MessageToSend
ThisMailSession.mailSend(ThisMailMessage)
ThisMailSession.mailLogoff()
DESTROY ThisMailSession

The email message typed into mle_messagetext is stored in the Instance Variable MessageToSend whenever the user changes the Text property of the control.  

Hit Counter

 

Last modified: Friday August 25, 2000.