smtpSetConfig (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.50 (4.34: iface) / 1.00.00


This function will set the configuration for the SMTP interface.

The SMTP configuration is stored in persistent memory and only needs to be set once.

 

Using secure connection

For NX32L devices a secure TLS (TLS v1.2, v1.1 or 1.0) connection can be established assuming that a matching X509 root certificate is present.

 

To use secure connection:

1. Ensure the root certificate needed to verify the mail server is present.

2. Set 'useTLS := TRUE' when calling smtpSetConfig.

 

 

Input:

IP : STRING

The IP address of the mail server (max. 40 characters).

 

Port : DINT (default 25)

The port of the mail server.

 

iface : SINT (default 0)

The network interface to use. 0 = Default network, 1 = Cellular network, 2 = LAN network, etc. (See Network)

Note: For backwards compatibility the cellular network is used as default network.

 

Sender : STRING

The mail address of the sender. (max. 40 characters).

 

Authenticate : BOOL

TRUE:

Use authentication.

FALSE:

Do not use authentication.

 

Username : STRING

The user name the device should use in order to connect to the mail server (max. 40 characters).

 

Password : STRING

The password the device should use in order to connect to the mail server (max. 40 characters).

 

UseTLS : BOOT (default FALSE)

TRUE:

Use secure connection.

FALSE:

Use insecure connection

 

Returns: INT

0

- Success.

-3

- Invalid parameter

 

 

Declaration:

FUNCTION smtpSetConfig : INT;
VAR_INPUT
   IP                 : STRING;
   Port               : DINT := 25;
   iface              : SINT := 0;
   Sender             : STRING;
   Authenticate       : BOOL;
   Username           : STRING;
   Password           : STRING;
   UseTLS             : BOOL := FALSE;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM example;
 
// Set SMTP config
smtpSetConfig(IP := "mail.server.com",
              Port := 25,
              iface := 1,
              Sender := strFormat(format := "\4@server.com", v4 := boardSerialNumber()),
              Authenticate := ON,
              Username := "DEVICE",
              Password := "12345");
 
BEGIN
   ...
END;
END_PROGRAM;