Y_CO_SendEmail
Parameters
| * | Parameter | Data Type | Description | Default |
|---|---|---|---|---|
| VAR_IN_OUT | ||||
| V | MessageBody | Yt_ByteArray4096 | The e-mail body as a 4096 element byte array. If a larger body is required, this declaration can be changed and the library recompiled. | |
| V | MessageData | Yt_CO_SMTP_Data | A user customized data structure for configuring the e-mail block. | |
| VAR_INPUT | ||||
| B | Execute | BOOL | Upon the rising edge, all other function block inputs are read and the function is initiated. To modify an input, change the value and re-trigger the execute input. | FALSE |
| V | BodyLength | UDINT | The length (number of bytes) of the e-mail body that will be sent. While not necessary it is highly suggested, see notes below. | UDINT#0 |
| VAR_OUTPUT | ||||
| B | Done | BOOL | Set high upon successfully sending an e-mail. | |
| B | Busy | BOOL | Set high upon the start of communications with the SMTP server and low when 'Done' or 'Error' go high. | |
| B | Error | BOOL | Set high when an error occurs during e-mail configuration and sending. Set low upon Execute being reset. | |
| E | ErrorID | UINT | If Error is true, this output provides the ErrorID. Cleared upon 'Execute' being reset. | |
| V | ErrorString | Yt_String256 | If 'Error' is true and it is an SMTP response code related error then this output contains the response string from the SMTP server. | |
Notes
- This function block will most likely only work with local network SMTP servers. Talk with your IT professional about connecting to a local SMTP server from a motion controller (see "Setup" below for more details about the required configuration).
- The "BodyLength" input is optional but highly suggested to reduce the packet size and the potential for large amounts of padding ("0") bytes on the recipients side. All examples include this Input and demonstrate how to get the correct length.
Error Description
Example
The example shown here sets up the block, creates a message body and sends an e-mail to external Gmail account.
The variable EmailBodyString is of type Yt_STRING256. Below is the configuration of the Yt_CO_SMTP_Data structure:
The most basic form of sending an e-mail is simply converting a string to a byte array via the STRING_TO_BUF function block. With the data structure shown above and this STRING_TO_BUF block, the email is configured and ready for use.
After toggling PrepareMessage, here is the result.
And to demonstrate the end result, here is the e-mail in the inbox of the Gmail account used. The sender and subject are both listed correctly and a portion of the send message can be seen.