Intouch Script Function Sample of SendMail

Posted on 1,755 views

Description

The SendMail() function sends an electronic mail message to a particular recipient. See Tech Support Script Function Library to install this function.

Use:

Result = SendMail(Recipient, Filename);

Recipient A Message tag or quoted text (example: “JOHN SMITH”) which represents the recipient’s name as entered in the To: field of the Mail client. Recipient is not the Post Office name.
Filename A Message tag or quoted text (example: “C:\REPORT.TXT” ) which represents the name of the file which will be used to construct the mail message. Filename is not an attachment. The ability to attach files is not available with SendMail. See below for more information on the contents of Filename.

If tagnames are specified, both Recipient and Filename need to be Message tags.

Return Value:

-1 Means it was unable to execute SendMail(). This may be caused by a low memory condition or that there may be a problem with the Mail client itself. If a problem persists, try sending mail manually outside of InTouch.
1 Means SendMail() was successful and the mail was sent to the Post Office.

Note SendMail() cannot tell you the delivery date and time or verify the delivery. The actual delivery of the mail is verified by the Post Office.

Details

SendMail() will send a mail message to Recipient (example: “Joe Smith”). The message content is in a text file specified by Filename. This file is not sent as an attachment but file’s contents are sent instead. The first line of the text file specifies the subject of the message. The remaining lines are the body of the message.

Upon execution of the SendMail() function the following Windows dialog box will appear notifying the user that an e-mail is being sent and requesting acknowledgement that this action is intended.

Figure 1. Dialog requesting confirmation that the e-mail is being sent intentionally

It is very important to understand that while the dialog shown in Figure 1 is visible InTouch stops all processing. For this reason it is strongly advised that the SendMail() function be used in an asynchronous quickfunction.

Example Script

The following is an example script that sends a mail message using SendMail(). Using this script, a mail message with the subject line: “Production Report” would be sent to the recipient Bill Gates.

{ This is an example of using the SendMail() Script function }
{ to send the contents of the file: C:\REPORT.TXT }

{ First, remove the file if it already exists }
FileDelete( “C:\REPORT.TXT” );

{ Now, insert the contents into the file }
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “Production Report”, 1 );
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “This report was sent from InTouch!”, 1 );
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “I’m going home.”, 1 );

{ Then send it to the manager of all managers… }
Result = SendMail( “Bill Gates”, “C:\REPORT.TXT” );

Description

The SendSMTPConfig() script function is used to configure settings used by the SendSMTPMail and SendSMTPMailwAttachment.

This function records the supplied configuration settings to the registry for use by the SendSMTPMail functions. These settings will override any corresponding supplied argument(s) to the SendSMTPMail functions.

If this function is not used the SendSMTPMail functions will use the supplied arguments to send the e-mail. SendSMTPConfig() does not return a value.

Please see Tech Support Script Function Library to install this function.

Use

SendSMTPConfig( HostName, PortNumber, LogOnMethod, LogonDomain, UserName, Password, SenderName, SenderEMail, TEXTorHTML, Unused, Unused, Unused, 0, 0 );

HostName A Message tag or quoted text (example: “MailServer”) which represents the name of the SMTP server to use to send the E-Mail.
PortNumber This field is used to set the port that the SMTP Server uses to send e-mails. This will normally be 25.
LogonMethod The SMTP Mail functions can be configured to login to the server or not with this setting. This an integer field. A value of 0 is used if the SMTP server is configured for anonymous access. If anonymous access is not configured enter a value greater than zero.
LogonDomain A Message tag or quoted text which represents the SMTP server name if the account used is a local server account. If a domain account will be used to authenticate, enter the domain name here.
UserName A Message tag or quoted text which represents the local or domain account name.
Password A Message tag or quoted text which represents the account password.
SenderName A Message tag or quoted text (example: “John Doe”) that will appear in the From field of the e-mail.
SenderEMailAddress A Message tag or quoted text (example: “[email protected]”) which would be considered the return address for the e-mail. This field can hold any valid e-mail address so the e-mail address for a responsible party can be used.
TEXTorHTML A Message tag or quoted text specifying the format of the e-mail body as Text or HTML.
Unused A Message tag or quoted text to be used for a future configuration requirement. Supply “Unused” for clarity.
Unused A Message tag or quoted text to be used for a future configuration requirement. Supply “Unused” for clarity.
Unused A Message tag or quoted text to be used for a future configuration requirement. Supply “Unused” for clarity.
0 An Integer tag or supplied value to be used for a future configuration requirement. Supply 0 for clarity.
0 An Integer tag or supplied value to be used for a future configuration requirement. Supply 0 for clarity.

Return Value

void This function does not return a value

Note: SendSMTPConfig() stores the supplied values in the registry for use by SendSMTPMail() and SendSMTPMailwAttachment().

Example Script

The following is an example script usage of SendSMTPConfig() to configure the SendSMTPMail functions to use an authenticated SMTP server to send an HTML message:

SendSMTPConfig( “MailServer”, 25, 1″, “MailServerDomain”, “johnd”, “wonderware”, “John Doe”, “[email protected]”, “HTML”, “Unused”, “Unused”, “Unused”, 0, 0);

Description

The SendSMTPClearConfig() script function is used to clear the settings configured by SendSMTPConfig().

After using this function to clear the registry settings configured by SendSMTPConfig() the SendSMTPMail functions will use their supplied arguments to send an e-mail. SendSMTPClearConfig() does not return a value.

See Tech Support Script Function Library to install this function.

Use

SendSMTPClearConfig( );

void No arguments are accepted.

Return Value

void This function does not return a value

Note: SendSMTPClearConfig() clears the registry stored values used by SendSMTPMail() and SendSMTPMailwAttachment(). Following the call to this function SendSMTPMail() and SendSMTPMailwAttachment() will use the supplied arguments to send an e-mail.

Example Script

The following is an example script usage of SendSMTPClearConfig() to reset the SendSMTPMail functions. Using this function ensures using supplied arguments to send an email.

SendSMTPClearConfig( );

Description

The SendSMTPMail() function sends an electronic mail message via an SMTP server, with Port 25 open, to a particular recipient. This function is used in conjunction with SendSMTPConfig() and SendSMTPClearConfig(). See Tech Support Script Function Library to install this function.

Use

Result = SendSMTPMail(SMTPServer, SenderEMailAddress, RecipientEMailAddress, SubjectLine, Filename);

SMTPServer A Message tag or quoted text (example: “MailServer”) which represents the name of the SMTP server used to send the E-Mail. This function does not support the username and password authentication required by most Internet Service Providers. It is recommended that the SMTPServer be local or available on the local area network containing the InTouch node. Once again Port 25 must be open
SenderEMailAddress A Message tag or quoted text (example: “[email protected]”) which would be considered the return address for the InTouch node sending the e-mail. This field can hold any valid e-mail address so the e-mail address for a responsible party can be used.
RecipientEMailAddress A Message tag or quoted text (example: “[email protected]”) that holds the address for the individual that should receive the e-mail.
SubjectLine A Message tag or quoted text (example: “Machine 1 Shift Production”) that holds the text that will be used for the e-mail Subject line.
Filename A Message tag or quoted text (example: “C:\REPORT.TXT” ) which represents the name of the file which will be used to construct the mail message. Filename is not an attachment. The ability to attach files is not available with SendSMTPMail (Use function SendSMTPMailwAttachment() to send attachments). See below for more information on the contents of Filename.

If tagnames are specified for the arguments, all tags need to be Message tags.

Return Value

0 Means it was unable to execute SendSMTPMail(). Check the SMTP Server status and the specified file Filename
1 Means SendSMTPMail() was successful and the mail was sent to the Post Office.

Note SendSMTPMail() cannot tell you the delivery date and time or verify the delivery. The actual delivery of the mail is verified by the Post Office.

Details

SendSMTPMail() will send a mail message to RecipientEMailAddress (example: [email protected]”). The message content is in a text file specified by Filename. This file is not sent as an attachment but file’s contents are sent instead. The contents of the file will be used as the body of the message.

It is worth noting that when executing this function a delay will occur which will interrupt InTouch. This delay will occur primarily while the SMTPServer is being contacted and while  Filename is being accessed.  For this reason, using this function in an asynchronous quickfunction should be considered.

Sample Script

The following is an sample script that sends a mail message using SendSMTPMail(). Using this script, a mail message with the subject line: “Today’s Report” would be sent to the recipient [email protected]. Assuming the name of the InTouch node “Machine1”, the e-mail would appear in Jane Doe’s InBox as being from “InTouch on Node Machine1”. The e-mail address associated with “InTouch on Node Machine1” will show as “[email protected]“.

{ This is an example of using the SendSMTPMail() Script function }
{ to send the contents of the file: C:\REPORT.TXT }

{ First, remove the file if it already exists }
FileDelete( “C:\REPORT.TXT” );

{ Now, insert the contents into the file }
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “Machine 1 Production Report”, 1 );
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “500,000 Widgets produced on Machine 1”, 1 );
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “This was a record run.”, 1 );

{ Then send it to the manager of all managers… }
Result = SendSMTPMail( “MailServer”, “[email protected]“, “[email protected]“, “Today’s Report”, “C:\REPORT.TXT” );

Description

The SendSMTPMailwAttachment() function sends an electronic mail message via an SMTP server, with Port 25 open, to a particular recipient. This function is used in conjunction with SendSMTPConfig() and SendSMTPClearConfig(). See Tech Support Script Function Library to install this function.

Use

Result = SendSMTPMailwAttachment(SMTPServer, SenderEMailAddress, RecipientEMailAddress, SubjectLine, Body, AttachmentFilename);

SMTPServer A Message tag or quoted text (example: “MailServer”) which represents the name of the SMTP server used to send the E-Mail. This function does not support the username and password authentication required by most Internet Service Providers. It is recommended that the SMTPServer be local or available on the local area network containing the InTouch node. Once again Port 25 must be open
SenderEMailAddress A Message tag or quoted text (example: “[email protected]”) which would be considered the return address for the InTouch node sending the e-mail. This field can hold any valid e-mail address so the e-mail address for a responsible party can be used.
RecipientEMailAddress A Message tag or quoted text (example: “[email protected]”) that holds the address for the individual that should receive the e-mail.
SubjectLine A Message tag or quoted text (example: “Machine 1 Shift Production”) that holds the text that will be used for the e-mail Subject line.
Body A Message tag or quoted text (example: “Attached is today’s Machine 1 shift production report.”) that holds the text that will be used for the body of the e-mail.
AttachmentFilename A Message tag or quoted text (example: “C:\REPORT.TXT” ) which represents the name of the file which will be attached to the e-mail.

If tagnames are specified for the arguments, all tags need to be Message tags.

Return Value

0 Means it was unable to execute SendSMTPMailwAttachment(). Check the SMTP Server status and the specified file Filename
1 Means SendSMTPMailwAttachment() was successful and the mail was sent to the Post Office.

Note: SendSMTPMailwAttachment() cannot tell you the delivery date and time or verify the delivery. The actual delivery of the mail is verified by the Post Office.

Details

SendSMTPMailwAttachment() will send a mail message to RecipientEMailAddress (example: [email protected]”). The message content is contained in the Body field. The AttachmentFilename field holds the path and name of the file to be attached to the e-mail.

It is worth noting that when executing this function a delay will occur which will interrupt InTouch. This delay will occur primarily while the SMTPServer is being contacted and while  AttachmentFilename is being accessed.  For this reason, using this function in an asynchronous quickfunction should be considered.

Example Script

The following is an example script that sends a mail message using SendSMTPMailwAttachment(). Using this script, a mail message with the subject line: “Today’s Report” would be sent to the recipient [email protected]. Assuming the name of the InTouch node “Machine1”, the e-mail would appear in Jane Doe’s InBox as being from “InTouch on Node Machine1”. The e-mail address associated with “InTouch on Node Machine1” will show as “[email protected]“.

{ This is an example of using the SendSMTPMailwAttachment() Script function }
{ to send the contents of the file: C:\REPORT.TXT }

{ First, remove the file if it already exists }
FileDelete( “C:\REPORT.TXT” );

{ Now, insert the contents into the file }
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “Machine 1 Production Report”, 1 );
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “500,000 Widgets produced on Machine 1”, 1 );
r = FileWriteMessage(“C:\REPORT.TXT”, -1, “This was a record run.”, 1 );

{ Then send it to the manager of all managers… }
Result = SendSMTPMailwAttachment( “MailServer”, “[email protected]“, “[email protected]“, “Today’s Report”, “Attached is today’s Machine 1 shift production report.”, “C:\REPORT.TXT” );

4 thoughts on “Intouch Script Function Sample of SendMail

  1. Microsoft Edge 17.17134 Microsoft Edge 17.17134 Windows 10 x64 Edition Windows 10 x64 Edition

    hello, I copy Wwtechsp.dll and Wwtechsp.wdf files to my InTouch directory,then I open the maker,use the functions of SendSMTPConfig() and SendSMTPMail() in a button.when I save,it comes a error:”Define SendSMTPConfig ?” or “Define SendSMTP Mail ?” so I don’t know why it let me to define! please help me ,weitting for your answer! hurry! thanks.

  2. Microsoft Edge 17.17134 Microsoft Edge 17.17134 Windows 10 x64 Edition Windows 10 x64 Edition

    Hi,I use the SendSMTPMail() together with SendSMTPClearConfig( ) and SendSMTPConfig() to send Email in Chinese language,then I find the Recipient E-Mail context is The statement.why? Our customer just want to view the Email information which from intouch alarm is chinese,they are poor in english.so please help me how to deal with the statement problem! Thank you very much.waitting for your reply!

    1. Firefox 52.0 Firefox 52.0 Windows 10 x64 Edition Windows 10 x64 Edition

      Sorry, this is a official plugin provide by Wonderware. I havent use it before.

Leave a Reply

Your email address will not be published. Required fields are marked *

75 − = 69