SendWithAttachments

TwinCAT TIA
Network E-Mail

ns=2;s=DEPRAG Smart/Network/EMailClient/SendWithAttachments

This command sends an e-mail message with attachments to all e-mail addresses stored in the MailAddressTo field. File attachments are passed in the AttachmentFilePaths field. Before using the functionality, the SMTP server must be set in the SmtpServerSettings settings.

Parameters:

    Content
    Text content of the e-mail message.

Returns:

    SendWithAttachments
    A variable of the OpcMethodReturnValueVoid type. The method has no command-specific return values.

Examples:

In addition to the parameters already explained, the following variables must be created / transferred for the implementation in TwinCAT 3:

Beckhoff parameter:

    EmailAddressArray
    A variable of the type "ARRAY[1..50] OF STRING(255)" in which the recipient e-mail addresses are stored.
    bEMailClientSendWithAttachments
    A boolean variable that can be used to trigger the execution of the SendWithAttachments command.
    OutputDataEMailClientSendWithAttachments
    An instance of the "ST_VoidOutputData" structure into which the return value of the SendWithAttachments command is written.
    hrEMailClientSendWithAttachments
    This can be used to monitor the execution of the command. Error codes have the type "HRESULT".
    fbEMailClient
    An instance of the "FB_EMailClient" function block supplied with the DEPRAG Smart library.
    sSubject
    A variable of the type "POINTER TO ARRAY[1..1000] OF BYTE" in which the subject of the e-mail message is stored.
    SizeOfSubject
    A UINT variable containing the length of the subject.
    sContent
    A variable of type "POINTER TO ARRAY[1..5000] OF BYTE" in which the text of the e-mail message is stored.
    SizeOfContent
    A UINT variable containing the length of the text.
    sMailAdressFrom
    A string of type "STRING(255)" specifying the sender e-mail address.
    nNumberOfAddressesToMailTo
    A UINT variable that reflects the number of recipient email addresses.
    EmailAttachmentsArray
    A variable of the type "ARRAY[1..50] OF STRING(255)" in which the file paths to the files to be attached are stored.
    ConnectionHandle
    "ConnectionHandle" received when establishing a connection between DEPRAG Smart Server and your OPC UA client.


VAR
   EmailAddressArray        : ARRAY[1..50] OF STRING(255) := ['employee@example.com'];
   EmailAttachmentsArray       : ARRAY[1..50] OF STRING(255) := ['C:\Test\text.txt'];
   bEMailClientSendWithAttachments       : BOOL;
   OutputDataEMailClientSendWithAttachments     : ST_VoidOutputData;
   hrEMailClientSend       : HRESULT;
   testShortByteArray : ARRAY[1..10] OF BYTE := [84, 101, 115, 116];
   testLongByteArray : ARRAY[1..1000] OF BYTE := [84, 101, 115, 116, 255, 84, 255];
   fbEMailClient         : FB_EMailClient;
END_VAR

hrEMailClientSendWithAttachments := fbEMailClient.EMailClientSendWithAttachments(
             bExecute       := bEMailClientSendWithAttachments,        
             ConnectionHandle    := depragSmartConnection.ConnectionHandle, 
             sMailAdressFrom     := 'test@deprag.de',                       
             MailAddressTo     := EmailAddressArray,                      
             nNumberOfAddressesToMailTo  := 1,                                      
             sSubject      := ADR(testShortByteArray),
             SizeOfSubject     := SIZEOF(testShortByteArray),
             sContent      := ADR(testLongByteArray),
             SizeOfContent     := SIZEOF(testLongByteArray),
             AttachmentFilePaths    := EmailAttachmentsArray,
             nNumberOfAttachmentFilePaths := 1,
             OutputData      => OutputDataEMailClientSendWithAttachments);
IF hrEMailClientSendWithAttachments <> S_FALSE THEN 
     bEMailClientSendWithAttachments := FALSE;
END_IF
                                                    

For examples and explanations regarding the calls of nodes via Siemens TIA Portal please refer to the sub-menu "Siemens TIA Portal" in section "Getting Started".