hub.eb?material_id=640&track_id=632

My First App - Part 3


In this third part we will create an Email Resource and use it to send an email when the send button is clicked.

An Email Resource acts an interface to an email service.

Steps


1

Create an Email Resource:

  1. Right-click on the myFirstApp Project and select New > Email Resource.
  2. Name the Email Resource myFirstAppEmail.
2

Configure the Email Resource:

  1. Click the Email Account button and select VerjSamples.
  2. Type &&email_from in the From field.
  3. Type &&email_to in the To field.
  4. Type &&email_subject in the Subject field.
  5. Type &&email_message in the Message field.
  6. In the Resource Fields panel, click (Build fields from email resource)
    This will automatically create a resource field for each of the && field substitution references.

Your Email Resource should look like this:

3

Add the Email Resource to myFirstApp:

  1. Open the Form editor for myFirstApp by double-clicking it in the Entity tree.
  2. Click Add Resource in the Resources view.
  3. Select myFirstAppEmail and click OK.
4

Map the Form's Fields to the Resource Fields:

  1. Right-click on myFirstAppEmail in the Resources view and select Show Mappings For Resource.
  2. Click the Auto-map button and click OK.
5

Send an email when the Send button is pressed:

  1. Open the Script editor for sendEmail by double-clicking it in the Entity tree.
  2. Add the following line before gotoPage:
    resources.myFirstAppEmail.sendmail();

Your sendEmail script should look like this:

importPackage(com.ebasetech.xi.api);
importPackage(com.ebasetech.xi.services);

resources.myFirstAppEmail.sendmail();

form.gotoPage(pages.success);
6

Test the Form in your browser:

  1. Click the Test  button in the main toolbar and press Submit in the resulting dialog.
  2. Fill in the fields, providing your own email address in the toEmail input.
  3. Press Send.

Clicking the Send button takes you to the success page and you should receive an email with your emailSubject and emailMessage.

Note, as this is a test email account, it may be worth checking your junk mailbox if the email doesn't appear.

Current Tutorial

Related