smtpOpen (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.50 / 1.00.00


This function will open the SMTP interface. Calling this function is required before the SMTP interface can be used.

Also see smtpClose for closing the SMTP interface when finished with the operations.

 

Prior to a message sent through smtpSend or smtpSendX, a SMTP configuration must be a set by using smtpSetConfig, and the configured network interface must have been opened using netOpen.

 

Input:

None.

 

Returns: INT

0

- Success.

-1

- General error.

-2

- Already open.

 

Declaration:

FUNCTION smtpOpen : INT;

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  alarm : BOOL;
END_VAR;
 
VAR
  fired   : BOOL;
END_VAR;
 
PROGRAM example;
VAR
  rc     : INT;
  Subject : STRING;
END_VAR;
 
  gsmPower(power := ON);
  netOpen(iface:=1);
  smtpOpen();
 
BEGIN
  // Is there an alarm
  IF alarm AND NOT fired THEN
     Subject := strFormat(format := "Device \4", v4 := boardSerialNumber());
     rc := smtpSend(Receiver := "devices@alarms.com",
                    Receiver_cc := "cc_devices@alarms.com",
                    Subject := Subject,
                    Message := "Alarm is triggered!");
    IF rc <> 0 THEN
        DebugFmt(message := "Error sending mail (errno=\1)", v1 := rc);
    ELSE
        DebugMsg(message := "Mail sent");
    END_IF;
  END_IF;
  fired := alarm;
END;
END_PROGRAM;