Form S_153FA: Email Demonstration A

LANSA

Form S_153FA: Email Demonstration A
Name: S_153FA

Description: The following RDMLX form demonstrates various aspects of email integration and the use of resuable part S_153RML.
FUNCTION OPTIONS(*DIRECT);
BEGIN_COM FORMPOSITION(ScreenCenter) HEIGHT(111) LEFT(391) TOP(183) WIDTH(514);
DEFINE_COM CLASS(#STD_TEXTL.Visual) NAME(#SEND_TO) CAPTION('Send to Email Address') DISPLAYPOSITION(1) LABELTYPE(Caption) LEFT(8) MARGINLEFT(120) PARENT(#COM_OWNER) TABPOSITION(2) TOP(16) WIDTH(393);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#BTN_SEND) BUTTONDEFAULT(True) CAPTION('Send Email ') DISPLAYPOSITION(2) ENABLED(False) LEFT(416) PARENT(#COM_OWNER) TABPOSITION(3) TOP(12);
DEFINE_COM CLASS(#S_153RML) NAME(#MAIL) DISPLAYPOSITION(3) PARENT(#COM_OWNER) VISIBLE(False);
DEFINE_COM CLASS(#STD_CODEL.Visual) NAME(#EMAIL_NUM) CAPTION('Email Number Assigned') DISPLAYPOSITION(4) LABELTYPE(Caption) LEFT(8) MARGINLEFT(120) PARENT(#COM_OWNER) READONLY(True) TABPOSITION(4) TABSTOP(False) TOP(54) VISIBLE(False) VISUALSTYLE(#VS_NOREAD) WIDTH(177);
;
Def_Cond *Recipient '#Send_To.Value *ne *blanks';
;
Define #LastTOAdr RefFld(#Std_TextL);
;
Define #EmailTot RefFld(#Date) Edit_Code(4) Length(5) Decimals(0) Default(0);
Define #EmailTotC *Char 5 To_Overlay(#EmailTot);
;
* ============================================================;
* Form Initialization - Restore the last email address used;
* ============================================================;
;
EvtRoutine Handling(#Com_Owner.Initialize);
Set #Com_Owner Caption(*Component_Desc);
Change #EMailTot 0;
Change #EMailTot *Remembered_Value_For_User;
Change #LastTOAdr *Remembered_Value_For_User;
Set #Send_To Value(#LastTOAdr);
Set #Btn_Send Enabled(*Recipient);
EndRoutine ;
;
* ============================================================;
* Form Termination - Remember first email address used;
* ============================================================;
;
EvtRoutine Handling(#Com_Owner.Closing);
Change #LastTOAdr #Send_To.Value;
EndRoutine ;
;
* ============================================================;
* Send the example email;
* ============================================================;
;
EVTROUTINE HANDLING(#BTN_SEND.Click);
;
* Set up the subject of the email;
;
Change #EmailTot '#EmailTot + 1';
Set #EMail_Num Value(#EmailTotC) Visible(True);
Use BConcat ('This is example Email message' #EmailTotC 'from' *Component) (#SysVar$Av);
Set #Mail Subject(#SysVar$Av);
;
* Insert the TO email address and make the visual email address the same as the user profile;
;
Invoke #Mail.InsertRecipient EMailAddress(#Send_To) VisualName(*User);
;
* Define example line 2 in two pieces;
;
Invoke #Mail.InsertItem Order(20) TextValue('This is the second') AppendCR(False);
Invoke #Mail.InsertItem Order(30) TextValue('line, but it was sent in two parts.') LeadingBlank(True);
;
* Define example line 3.;
* Note how the item to contain the number is being assigned a symbolic;
* name (ie: NumberinLine3). We will set the actual value of this item later.;
;
Invoke #Mail.InsertItem Order(40) TextValue('This is the third line and it contains a number -->') AppendCR(False);
Invoke #Mail.InsertItem Order(50) SymName(NumberinLine3) AppendCR(False) LeadingBlank(True);
Invoke #Mail.InsertItem Order(60) TextValue('<--- right in the middle of it.') LeadingBlank(True);
;
* Define example lines 4 and 5;
;
Invoke #Mail.InsertItem Order(70) TextValue('The next line contains two numbers all by themselves.');
Invoke #Mail.InsertItem Order(80) NumericValue(-9876.54) Decimals(2) AppendCR(False);
Invoke #Mail.InsertItem Order(85) TextValue('and') AppendCR(False) LeadingBlank(True);
Invoke #Mail.InsertItem Order(90) NumericValue(1234567890.12345) Decimals(5) LeadingBlank(True);
;
* Define example lines 6;
;
Invoke #Mail.InsertItem Order(100) TextValue('This is the last line in this example email.');
;
* Define example line 1;
* Note how it can be defined last but ordered so that it is sent first.;
;
Invoke #Mail.InsertItem Order(10) TextValue('This is the first line in this example email.');
;
* Insert the number's value into line 3. Note how this can be done "by name" at any time;
* after the item has been inserted ... but you need to give it a symbolic name to (re)reference it.;
;
Invoke #Mail.UpdateItem SymName(NumberinLine3) NumericValue(14.562) Decimals(4);
;
* Send the mail defined in the component;
;
Invoke #Mail.Send;
;
* Close the mail component (which clears all data inside it);
;
Invoke #Mail.Close;
;
* Finished;
;
ENDROUTINE ;
;
* ============================================================;
* Put up a message box if an unexpected error is detected;
* ============================================================;
;
EvtRoutine Handling(#Mail.MailErrorDetected);
Use Message_Box_Show (ok ok error *component 'Unexpected error when sending email.');
EndRoutine ;
;
* ==================================================================;
* Only enable the send button when there is something in the address;
* ==================================================================;
;
EVTROUTINE HANDLING(#Send_To.Changed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
Set #Btn_Send Enabled(*Recipient);
ENDROUTINE ;
;
END_COM ;