Mastering PowerBuilder

HomePrevious Lesson: Customizing Error Service Behavior
Next Lesson: Error Logging & Other Services

Error Service - e-Mail Notifications

If you would like to send an e-mail automatically when an error occurs, you can do so with few function calls. PFC error service provides the required functionality. First, you need to specify the severity level above which you want to send an e-mail notification. Write the following in the pfc_SystemError event.
inv_Error.ofSetNotifySeverity(10)

The above function says, send e-mail notification only for errors with severity level 10 or above. Now, connect to the e-mail system. Before that, declare the following instance variables:
n_ms ims_MailSession
String ls_EMailList[]

Write the following code to the pfc_SystemError event at the n_cst_AppManager object.
MailReturnCode lmrc_RetCode
ims_MailSession = CREATE n_ms
lmrc_RetCode = ims_MailSession.MailLogOn()
If lmrc_RetCode <> MailReturnSuccess! Then
   MessageBox("Mail Login Error", &
      "Unable to Login to " + "the Mail System.")
   Return
End If
li_rc = inv_Error.of_SetNotifyConnection(ims_MailSession)
If li_rc = -1 Then
   MessageBox("Mail Error",
      "Unable to use the mail session.")
   Return
End if
ls_EMailList[1] = "prasad bodepudi"
li_rc = inv_Error.of_SetNotifyWho(ls_EMailList[])

We are creating a mail session and logging into the mail system using the MailLogOn(). Depending on the mail system settings, either you will be prompted for your login details or you log into the mail system automatically. Then we are asking the PFC to use the mail session we just created for the error e-mail notification.

We populate the user names whom we want to inform when an error occurs in an array and ask the PFC to use that users list. Now, when you call of_Message() at inv_Error object, PowerBuilder sends e-mails to each user listed in the user list. Make sure to destroy the object in the n_cst_AppManager�s destructor event.
If IsValid( ims_MailSession) Then DESTROY ims_MailSession
HomePrevious Lesson: Customizing Error Service Behavior
Next Lesson: Error Logging & Other Services