FP_SMTP_SET_CONNECTION

Server settings for SMTP connection

This FP instruction defines the server settings for the connection to the SMTP client specified in the CPU according to specified parameters.

Parameters

Input

sAccount(STRING)

Set the account data with names and addresses as well as port number and authentication method.

  • Source name (optional parameter)

    Keyword: NAME

  • Source e-mail address (required parameter)

    Keyword: FROM

    Syntax: 'FROM='

  • IP address or host name (required parameter).

    • IP address

      For an IP address, specify the keyword IPv4 or IPv6 at the beginning.

      Syntax for IPv4: e.g. 'IPv4=111.122.133.144'

      Syntax for IPv6: e.g. 'IPv6=1111:122:2:1555:0:0:1888'

      Please note that for IPv4 addresses there are range restrictions. When an invalid IP address is specified with an instruction, there will be no operation error but the output bError will be set to TRUE.

    • Host name

      Keyword: HOST

      Syntax: 'HOST=SMTP.pidsx.com'

  • Port number (optional parameter)

    Keyword: 'PORT'

    Syntax: 'PORT=xxxxx' (default: 25)

    Range: 1–65535

  • SSL3/TSL1 authentication (optional parameter). Specify whether or not to use SSL3/TSL1 authentication.

    Keywords:

    • SSL: Use SSL3/TLS1

    • NON: SSL3/TLS1 not used (default)

Examples:

  1. Set FP7_001 as the source name, "pana@pana.com" as the source e-mail address, 102.244.2.110 as the IP address and use port 25 with SSL3/TLS1 authentication: 'NAME=FP7_001,FROM=pana@pana.com,IPv4=192.255.2.10,PORT=25,SSL'

  2. Keep the source name as is, set "sunx@sunx.com" as the source e-mail address, 1222::a8dd:0:0:6666 as the IP address and use port 100 with SSL3/TLS1 authentication: ',FROM=sunx@sunx.com,IPv6=1111:1222::a8dd:0:0:6666,PORT=100,SSL'

  3. Set FP7_002 as the source name, "pewsunx@pewsunx.com" as the source e-mail address, "SMTPmailserver.com" as the host name and use port 1000 without authentication: 'NAME=FP7_002,FROM=pewsunx@pewsunx.com,HOST=SMTPmailserver.com,PORT=1000,NON'

  4. Set FP7_002 as the source name, "pewsunx@pewsunx.com" as the source e-mail address, "SMTPmailserver.com" as the host name. Do not change the settings for port number and authentication: 'NAME=FP7_002,FROM=pewsunx@pewsunx.com,HOST=SMTPmailserver.com'

sLogin(STRING)

Set the login data

  • SMTP authentication method (required keyword)

    Keywords:

    • CRAM: CRAM-MD5 is used

    • PLAIN1: PLAIN1 (ID/PASS) is used

    • PLAIN2: PLAIN2 (ID/PASS) is used

    • LOGIN: LOGIN is used

  • Account (max. 32 characters)

    Keyword: ACCOUNT

    Syntax: 'ACCOUNT=xxx' (default: root). Use 'ACCOUNT=' to delete the account.

  • Password (max. 32 characters, upper and lower case characters are allowed)

    Keyword: PASS

    Syntax: 'PASS=xxx' (default: root). Use 'PASS=' to delete the password.

For this parameter, there are two additional keywords available:
  • NOUSE: The setting for the SMTP authentication method will be ignored.

  • KEEP: Keeps the current login settings.

Examples:

  1. Set CRAM-MD5 as the SMTP authentication method for the account "sunx" with the password "control": 'CRAM,ACCOUNT=sunx,PASS=control'

  2. Set CRAM-MD5 as the SMTP authentication method for the account "root" and delete the password: 'CRAM,ACCOUNT=root,PASS='

  3. Set PLAIN1 as the SMTP authentication method, delete the account name, use the password "SUNX": 'PLAIN1,ACCOUNT=,PASS=SUNX'

  4. Set PLAIN2 as the SMTP authentication method, delete the account name and the password: 'PLAIN2,ACCOUNT=,PASS='

  5. Set LOGIN as the SMTP authentication method for the account "panasonic" and keep the password that has already been set: 'PLAIN2,ACCOUNT=panasonic'

  6. Set CRAM-MD5 as the SMTP authentication method for the account name that has already been specified and set the password "SUNX": 'CRAM,,PASS=SUNX'

  7. Do not use an SMTP authentication method, do not use an account, do not change the password: 'NOUSE'

  8. Keep the SMTP authentication method, the account, and the password: 'KEEP'

sCommunication(STRING)

Set optional communication parameters as required. Note that the default e-mail language is set to Japanese.

  • Maximum e-mail size

    Keyword: MAILSIZE

    Syntax: 'MAILSIZE=xxx' (default: 100)

    Range: 1–10240KB

  • Connection timeout

    Keyword: TOUT

    Syntax: 'TOUT=xxx' (default: 60 seconds)

    Range: 30–300 seconds

  • Number of retries

    Keyword: RTRY

    Syntax: 'RTRY=x' (default: 3 times)

    Range: 0–3

  • Retry interval

    Keyword: RTTM

    Syntax: 'RTTM=xxxxx' (default: 600 seconds)

    Range: 10–86400 seconds

    The value can be specified by 10 seconds. It is rounded down to the 10.

    Example: When you specify 38 seconds, 30 seconds are set.

  • Language to be used for e-mail subject and text.

    Keywords:

    • JPN: Japanese (default)

    • ENG: English

For this parameter, there are two additional keywords available:
  • INITIAL: Resets connection timeout, number of retries, and the retry interval to the default settings.

  • KEEP: Keeps the current communication settings.

Examples:

  1. Set maximum e-mail size: 1000KB, connection timeout: 30 seconds, number of retries: 2, retry interval: 500 seconds, e-mail language: Japanese: 'MAILSIZE=1000,TOUT=30,RTRY=2,RTTM=500,JPN'

  2. Set maximum e-mail size: 10000KB, connection timeout: 270 seconds, no retries, retry interval: 4900 seconds, e-mail language: English: 'MAILSIZE=10000,TOUT=270,RTRY=0,RTTM=4900,ENG'

  3. Set maximum e-mail size: 500KB, connection timeout: 30 seconds, number of retries: 3, retry interval: 200 seconds, e-mail language: do not change: 'MAILSIZE=500,TOUT=30,RTRY=3,RTTM=200'

  4. Set maximum e-mail size: 5000KB, connection timeout: do not change, number of retries: 5, retry interval: 3000 seconds, e-mail language: English: 'MAILSIZE=5000,,RTRY=5,RTTM=3000,ENG'

  5. Reset to default settings (maximum e-mail size: 100KB, connection timeout: 60 seconds, number of retries: 3, retry interval: 600 seconds, default e-mail language: Japanese): 'INITIAL'

  6. Keep all the current settings: 'KEEP'

Output

bError (BOOL)

Turns to TRUE under the following conditions:

  • if a timeout of the connection is exceeded

  • if an IP address is invalid

When an error occurs, check the system variable sys_iEthernetConnectionErrorCode for the error code number.

Remarks

  • Separate all keyword entries by comma. e.g. 'NAME=abcd,FROM=sender@server.com'

  • The number of characters for string data must not exceed 256.

  • This instruction is not available in interrupt programs.

  • Upper and lower case characters can be used for specifying keywords. However, the subject, the e-mail text, and the file name of the attachment are case-sensitive.

  • Before you execute the instruction, make sure that sys_bIsEthernetInitializing is FALSE. sys_bIsEthernetInitializing turns to TRUE when the instruction is executed. When you execute the instruction while sys_bIsEthernetInitializing is TRUE, an error occurs.

  • The instruction can only be executed when the transfer request flag for the specified transfer setting or the specified nLogID number is FALSE. When the transfer request flag is TRUE, an operation error occurs.

  • When this instruction has been executed successfully, the system variables sys_bIsCarry and sys_iEthernetConnectionErrorCode are reset.

  • When an error occurs, check the system variable sys_iEthernetConnectionErrorCode for the error code number.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if a value specified for a parameter is outside the permissible range.

  • if the same keyword is specified more than once

  • if the e-mail transmission request flag for the specified transfer setting is "TRUE: Transfer requested".

  • if the transfer request flag for a specified nLogID number is TRUE, e.g. if sys_blsLog0DataRecordingActive is TRUE.

  • if the instruction is executed in an interrupt program

  • if the number of characters for string data exceeds 256.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if a value specified for a parameter is outside the permissible range.

  • if the same keyword is specified more than once

  • if the e-mail transmission request flag for the specified transfer setting is "TRUE: Transfer requested".

  • if the transfer request flag for a specified nLogID number is TRUE, e.g. if sys_blsLog0DataRecordingActive is TRUE.

  • if the instruction is executed in an interrupt program

  • if the number of characters for string data exceeds 256.

sys_bIsCarry (turns to TRUE for one scan)
  • if the instruction is executed with an incorrect IP address, sys_iEthernetConnectionErrorCode is set to "1: Incorrect IP address is specified"

  • if the instruction is executed during the initialization of Ethernet, sys_iEthernetConnectionErrorCode is set to "11: Ethernet is being initialized".

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		bError: BOOL:=FALSE;
		bSetConnection: BOOL:=FALSE;
	END_VAR

POU body

If bSetConnection changes from FALSE to TRUE and sys_bIsEthernetInitializing is FALSE, the instruction is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 12 ;
        NETWORK_BODY
B(B_VARIN,,'NAME=FP7_001~FROM=pewsunx@pewsunx.com~HOST=smtpmailserver.com~PORT=1000~NON',37,6,39,8,);
B(B_VARIN,,'CRAM~ ACCOUNT=sunx~PASS=control',37,7,39,9,);
B(B_VARIN,,'MAILSIZE=1000~TOUT=30~RTRY=2~RTTM=500~ENG',37,8,39,10,);
B(B_CONTACT,,bSetConnection,4,1,6,3,R);
B(B_VAROUT,,bError,53,6,55,8,);
B(B_CONTACT,,sys_bIsEthernetInitializing,13,1,15,3,N);
B(B_F,FP_SMTP_SET_CONNECTION!,,39,4,53,10,,?DEN?DsAccount?DsLogin?DsCommunication?AENO?CbError);
L(6,2,13,2);
L(1,2,4,2);
L(15,2,15,6);
L(15,6,39,6);
L(1,0,1,12);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF DF(bSetConnection) And not sys_bIsEthernetInitializing then
    FP_SMTP_SET_CONNECTION(sAccount := 'NAME=FP7_001,FROM=pewsunx@pewsunx.com,HOST=smtpmailserver.com,PORT=1000,NON',
                           sLogin := 'CRAM, ACCOUNT=sunx,PASS=control',
                           sCommunication := 'MAILSIZE=1000,TOUT=30,RTRY=2,RTTM=500,ENG', 
                           bError => bError);
END_IF;

Modified on: 2024-03-06Feedback on this pagePanasonic hotline