Step 5. Test your Configuration

Use this step to confirm you have completed the previous steps correctly. You will need access to another IBM i or a PC to which you will send the test mail message.

1.  Send a mail message using OfficeVision or the SNDDST command to your test recipient (as described in Step 2).

2.  Send a mail message from a LANSA function using the Email Built-In Functions. You may use the following sample function or create one of your own. To keep the example simple we have omitted error handling, but you would normally check the return codes in your real-life application:

FUNCTION OPTIONS(*DIRECT);

********** COMMENT();

********** COMMENT(Working fields, lists and groups);

********** COMMENT();

DEFINE FIELD(#ORGL) TYPE(*CHAR) LENGTH(60) LABEL('From') DESC( 'Mail message originator');

DEFINE FIELD(#RCPL) TYPE(*CHAR) LENGTH(60) LABEL('To') DESC('Mail message recipient');

DEFINE FIELD(#SUBJECT) TYPE(*CHAR) LENGTH(60) LABEL('Subject') DESC('Mail message subject');

DEFINE FIELD(#RET_CODE) TYPE(*CHAR) LENGTH(2) DESC('BIF returncode');

GROUP_BY NAME(#PANELDATA) FIELDS(#ORGL #RCPL #SUBJECT);

********** COMMENT();

BEGIN_LOOP;

REQUEST FIELDS(#PANELDATA)

********** COMMENT(Start a mail message);

USE BUILTIN(MAIL_START) TO_GET(#RET_CODE)

********** COMMENT(Add the originator);

USE BUILTIN(MAIL_ADD_ORIGINATOR) WITH_ARGS(#ORGL) TO_GET (#RET_CODE);

********** COMMENT(Add the recipient);

USE BUILTIN(MAIL_ADD_RECIPIENT) WITH_ARGS (TO #RCPL) TO_GET(#RET_CODE); 

********** COMMENT(Set the mail message subject);

USE BUILTIN(MAIL_SET_SUBJECT) WITH_ARGS(#SUBJECT) TO_GET (#RET_CODE);

********** COMMENT(Send the mail message);

USE BUILTIN(MAIL_SEND) TO_GET(#RET_CODE);

END_LOOP;

RETURN;