How Do I ... ?

Send an Email

 

 

Any computer with an internet connection can send email very easily using Stardraw Control.

 

Practical uses for this within your project might be to automatically email a support account with diagnostics messages or error conditions, such as if a devices fails to respond to a command, or if a device raises an unexpected alert of some kind.

 

Online Resources

There is a multimedia walk-through of these techniques in the online Technical Resources.

 

You Will Need...

To send email, you need to know the mail server and account settings for the internet connection that the Stardraw executable will be running on.  This would typically be your customer's ISP Internet Service Provider. server and account details.

 

You need to know:

 

Notes

If a firewall is installed on the customer's computer or network, you will need to ensure that TCP/IP port 25 is open for outbound communication.  Some firewalls refer to this as the SMTP Port.

You can test this using your own ISP and email account settings, but do remember to change them to your customer's settings before you deploy your project.

 

Configuring SMTP Devices

To add support for sending mail, the first step is to add an SMTP Server device to your project and configure its design-time properties

 

To add an SMTP Server

  1. In the Topology View, locate the Email SMTP Server device in the Generic Control category of the Stardraw Control Products List.

  2. Click and drag the device to add it to your topology.

  3. Add a connection from your Computer's Ethernet port to the SMTP port of the new device.

 

To configure an SMTP Server

  1. Select the new device: its name and port will be displayed in the Property Grid, and expand the SMTP port to view all the available properties.

  2. Change the SMTPServer property to the IPS's mail server address you obtained earlier.

  3. Change the UserName property to your customer's user name or log-in name.

  4. Change the Password property to the customer's password.

  5. Change the From property to the customer's email address so that you can identify the sender.

  6. Change the To property to the email address that you wish emails to be sent.

  7. Change the Subject property to a short phrase that will enable you to identify the context of the message, e.g. "Stardraw Alert".

  8. Change the Body property to contain the message you wish to send.

 

Notes

The settings you configure here become the default values for the device, however you can change any of these properties at run-time before sending a message, such as the Subject and Body, using Actions.  The next section describes how to do this.

Normally you would only require one SMTP Server device in your topology, however a second instance could be added if communication with a different mail server were required.

 

Controlling an SMTP Device

The most basic control of an SMTP Device is to send an email with the default subject and message.  Further run-time control over the contents of the Subject and Body properties, and even the To and From email addresses is also possible.

 

Sending an email

To send an email in response to any device or control Event, using the settings you configured above:

  1. In the Forms View, locate the form or control that fires the Event you wish to capture.

  2. Open the Actions editor dialog, and select the desired Event from the toolbar.

  3. Add the following Action to call the Send method:
    Devices
    Email (1)SMTPSend

  4. Click Ok to close the Actions dialog.

 

When the project executable is run, an email will be sent in response to the Event you configured.

 

Changing SMTP Server properties

To reconfigure email properties at run-time before sending an email:

  1. Open the Actions editor dialog, and select the desired Event from the toolbar.

  2. Add the following Action to modify the Subject property:
    Devices
    Email (1)SMTPSet Subject to – Variables

  3. In the Enter value field, type "Stardraw Alert: Test"

  4. Add another Action to send the email:
    Devices
    Email (1)SMTPSend

  5. Click Ok to close the Actions dialog.

 

When an email is sent in response to the Event the message will contain the new subject.

 

Advanced Control

SMTP Server properties can also be accessed from within a Script.  The controllable properties and methods are:

 

This is an advanced topic and requires programming knowledge.  Please refer to Access a Device from a Script for more information.

 

See Also

Script Component