CnfEmail

This function configures the email settings used by other features in the project that can send email, such as Alarm worksheets and the SendEmail and SendEmailExt functions.

Function Group Execution Windows Embedded Thin Client Mobile Access
CnfEmail Email Synchronous Supported Supported, except for encryption Supported Executed on Server

Syntax

  CnfEmail( strSMTP, strFrom, strPOP3, strUser, strPassword, optNumTimeout, optNumAuthType, optStrSMTPUser, optStrSMTPPassword )  
Web Studio Help s2fr function email cnfemail.xml d112462e157 CnfEmail
strSMTP
The hostname or IP address of the outgoing email server, which is also known as the SMTP server. You can include a port number if the server does not use one of the standard SMTP ports.
Note: For projects that will run on Windows Embedded devices, you must specify an IP address.
strFrom
The email address from which emails will be sent and at which emails may be received. This should be a valid address on the POP3 server (see strPOP3 below).
strPOP3
The hostname or IP address of the incoming email server, which is also known as the POP3 server. You can include a port number if the server does not use one of the standard POP3 ports.
Note: For projects that will run on Windows Embedded devices, you must specify an IP address.
strUser
The username to be used to log onto the POP3 server.
strPassword
The password to be used to log onto the POP3 server.
optNumTimeout
The timeout limit (in seconds) to be used when sending email. If no response is received from the SMTP server within this period of time, then the operation is aborted.

This is an optional parameter; if no timeout is specified, then the project will keep trying forever until it receives a response. You should specify some timeout, however, to make sure that your project won’t freeze.

optNumAuthType
optStrSMTPUser
optStrSMTPPassword
By default, SMTP servers do not require authentication for outgoing email. If your server does require authentication, set optNumAuthType to 1 (unencrypted) or 2 (encrypted via TLS/SSL), and then specify the username and password. (If your SMTP username and password are the same as your POP3 username and password, then you can skip optStrSMTPUser and optStrSMTPPassword. The project will automatically use the values from strUser and strPassword.)
Note: Encryption via TLS/SSL is not supported in projects running on Windows Embedded target systems.

Returned value

Value Description
0 Success
1 Invalid format for strSMTP
2 Invalid format for strFrom
3 Invalid format for strPOP3
4 Invalid format for strUser
5 Invalid format for strPassword
6 Invalid format for optNumTimeout
7 Wrong number of parameters
8 Error getting host IP address (invalid POP3 server)
9 Error connecting to POP3 server
10 Error sending username
11 Error sending password
12 SMTP server does not support selected authentication mode
13 Invalid SMTP username
14 Authentication failed

Notes

The email configuration created by this function works only within the Windows process where the function was called.

For example, if you place a Button object in a screen and then set the object to call this function when it is pressed, the resulting email configuration will work only on the Client station where the screen is displayed and the button is pressed. It will not work on any other Client stations nor on the Server station, because the project viewer running on the Client station only exchanges data (i.e., changes in tag values) with the data server running on the Server station. One cannot directly call functions on the other; it can only use triggers to force the other to call functions. Please note that is true even when the Client station and the Server station are the same physical device, because the project viewer and the data server are two separate processes in Windows.

If you want an email configuration to apply to your project’s background tasks — for example, to be able to send emails when alarms become active — then you must either use the E-mail Settings dialog to configure default settings for the entire project OR call this function in some place like the project’s Startup Script, a Script Group, or a Math worksheet.

Examples

  CnfEmail( "smtp.company.com", "Robert@company.com", "pop.company.com", "RobertH", "Shades556", 100 )  
  CnfEmail( "smtp.company.com:4455", "Robert@company.com", "pop.company.com:9900", "RobertH", "Shades556", 5, 1 )  
  CnfEmail( "195.11.22.33:4455", "Robert@company.com", "195.66.77.88:9900", "RobertH", "Shades556", 5, 2, "JohnS", "abcd1234" )  

CnfEmail