SendMail

(VTScada-Layer function. Must be called with a leading backslash.)

Description: Sends a string to an email server using the Simple Mail Transport Protocol (SMTP)
Returns: Nothing
Usage: Script Only.
Function Groups: Email
Related to: ValidateEmailAddrs
Format: \SendMail(Server, To, From, Subject, Message, Error [,Attachments, AttachmentStreams, OptionalHeaders, ErrorText, SenderMailbox, Username, Password, UseTLS, Bcc, Charset, Port, UseOauth2, OAuth2GrantID, EncryptedSettings, ContentType])
Parameters:  
Server
Required. Any text or buffer expression of the mail server name or IP address
To
Required. Any text or buffer expression of the address of destination
From
Required. Any text or buffer expression of the address of the person from whom the mail is from
Subject
Required. Any text or buffer expression of the subject of the message
Message
Required. Any text or buffer expression of the message - no attachments
Error

Required. A pointer to an error variable, set to 0 if OK. The Error parameter should initially be set Invalid by the caller. When this method is done, it will set Error to one of the following values:

The following error codes are produced by VTScada. Your email server may produce others.

Error

Meaning

0

Mail has been successfully sent.

1

Unable to open a connection to the server.

2

Server did not send a good SMTP welcome message.

3

Server rejected SMTP HELO message.

4

Server rejected SMTP MAIL message.

5

Server rejected SMTP RCPT message.

6

Server rejected SMTP DATA message.

7

Server rejected message body.

8

Badly formatted TO: address.

9

Server does not support AUTH.

10

Server does not support implemented AUTH. mechanisms.

11

Failure to login to SMTP server.

12

TLS wanted for SMTP, but not available

13

TLS unavailable or negotiation with server failed

14

Badly formatted bcc address

Attachments
An optional parameter that is an array of file names to be attached to the email message.
AttachmentStreams
An optional parallel array of attachment streams.
OptionalHeaders
A string of optional MIME headers, separated by CRLF.
ErrorText
An optional pointer to the variable that holds the phrase key of the error message. Use \GetPhrase() to translate this ID to the language currently in use.
SenderMailbox
An optional parameter which is the SMTP reverse path. SenderMailbox overrides the From parameter. This parameter may be used as an alternative to the From parameter when specifying the "MAIL FROM" address in the SMTP.
The From parameter would still be used when specifying the "From:" address in the email header. SenderMailbox should be used only when an email is intended to look like it came from a particular address, but has actually originated from another address.
Username
Allows a user name to be provided to email servers that require authentication.
Password
Allows a password to be provided to email servers that require authentication.
UseTLS
Boolean to indicate that transport layer security should be used.
Bcc
Optional list of recipients, who should receive a bcc copy of the message.
Charset
Optional. Text string to be used for MIME character set.
Port
Optional numeric. Use to specify which port the SMTP server should use. If not provided, the value of the SMTPPort application setting is used, defaulting to 25.
UseOAuth2
Optional Boolean. Set TRUE use Auth
OAuth2GrantID
Text. Must be set if UseOAuth2 is TRUE. The Grant ID
EncryptedSettings
Optional text. A set of encrypted mail settings to use.
ContentType
Body content type (text/plain, text/html)
Comments:

This function opens a TCP/IP socked on port 25 (or other if specified) of the specified mail server. The Message is then sent using the SMTP protocol.
If both Username and Password are valid, then SendMail will attempt to login to the mail server before sending the email message. If the server does not support authentication, then SendMail will abort with an error message.
If both Username and Password are valid, but the server does not support PLAIN authentication, then SendMail will abort with an error.
If either Username or Password is missing or invalid, then the message will be sent without a login attempt.

The To: address will accept a string that conforms to the address-list ABNF from RFC 5322.

If using OAuth2 and the server does not offer XOAUTH2 as an authentication method then error 10 is returned.

Example:

\SendMail("192.168.0.201",
           "sales@trihedral.com",
           "vts@trihedral.com",
           "Great Product!",
           "VTScada is Great\n\rMust buy lots!",
           &ErrorCode);