Update cookies preferences
Promotic

Preconfiguration "Sending the e-mails by the application"

This preconfiguration can be activated when creating a new object (e.g. by "New object ..." in the context menu of the object or by pressing the Insert key after selecting the object).
 
This preconfiguration is included in the "/ Communication / Protocols and other communications / Email" group.
 
This preconfiguration can be created in the PmaFolder, PmaRoot or PmaPrototype object.

- The preconfiguration creates an object of the PmaFolder type containing 4 methods. Each of them uses a different technology for sending e-mails, but use the same parameters sTo, sSubject, sBody. At the beginning, there are the variables that set up the connection to the SMTP server.
- The preconfiguration also includes a panel for sending messages, but it is not necessary for communication.
It contains Pmg objects used for entering the receiver e-mail address, the message subject and the message body. There is also a PmgButton object, that calls the designer "SendEmail" method with the defined parameters in the onButtonUp event.
- In the window that appears before the object is created, it is necessary to enter the information needed for SMTP server configuration and message sender identification.
- The preconfiguration is created including the panel (object of the PmaPanel type) is functional also as Web panel. In order to make the preconfiguration functional also on the Web, it is necessary to enable the object of the PmaPanel type for the Web (on the "Web server" tab).


The panel method SendEmail can be called anywhere in the application.
These configurators can be set before the preconfiguration is created:
The name of created objectName of the object created in the Pma object tree.
The maximum name length is 30 characters.
This is a system name, so it must contain only alphanumeric and must not contain any diacritics (i.e. national dependent characters), empty string, spaces and first character must not be a number.
Default: "SendEmail"
SMTP server address
Server port (465, 587, ..)
Mail address sender
User identification of the sender on the SMTP server
Sender's user password on the SMTP server
Script to send an email using CDO technology:
JavaScriptVBScriptSelect and copy to clipboard

var nSendUsing, oMsg, oFlds, nSmtpAuthenticate, sSmtpServer, sFrom, sUserName, sPassword, nSmtpServerPort, bSmtpUseSsl, nSmtpConnectionTimeout;

nSendUsing = 2;   // 1 = Send message using the local SMTP service pickup directory, 2 = Send the message using the network (SMTP over the network)
sSmtpServer = "smtp.aol.com";   // Name or IP address of Remote SMTP Server
nSmtpAuthenticate = 1;   // Type of authentication, NONE=0, Basic=1 (Base64 encoded), NTLM=2
sFrom = "you@aol.com";   // Mail address sender
sUserName = "you@aol.com";   // User identification of the sender on the SMTP server
sPassword = "******";   // Sender's user password on the SMTP server
nSmtpServerPort = 465;   // Server port (465, 587, ..)
bSmtpUseSsl = true;   // Use SSL for the connection (false or true)
nSmtpConnectionTimeout = 60;   // Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)

oMsg = Pm.AxGetObject("new", "CDO.Message");
oMsg.BodyPart.Charset = "utf-8";   // "windows-1252" or "iso-8859-2" ...
oMsg.Subject = "Test email from PROMOTIC";
oMsg.From = sFrom;
oMsg.To = "xxxx@yahoo.com";
oMsg.TextBody = "Test email from PROMOTIC..\nIt was sent using SMTP authentication";
// oMsg.HTMLBody = "<h1>Test email from PROMOTIC..</h1><p>It was sent using SMTP authentication.</p>
oMsg.Addattachment("c:/temp/Text.txt");
// oMsg.Addattachment("c:/temp/Text2.txt");

// This section provides the configuration information for the remote SMTP server
oFlds = oMsg.Configuration.Fields;
oFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = nSendUsing;
oFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSmtpServer;
oFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = nSmtpAuthenticate;
oFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sUserName;
oFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = sPassword;
oFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = nSmtpServerPort;
oFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = bSmtpUseSsl;
oFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = nSmtpConnectionTimeout;
oFlds.Update();
// End of remote SMTP server configuration section

oMsg.Send();


http://www.w3schools.com/asp/asp_send_email.asp

Script to send an email using CURL technology:
JavaScriptSelect and copy to clipboard

var sSmtp = "smtps://smtp.aol.com:465";
var sFrom = "name@aol.com";
var sUser = "'nameid:password'";
var sPath = Pm.DiscGetPath("#cfg:");
var sFileName = "email_body.txt";

var sTo = "test@gmail.com";
var sSubject = "Test send mail";
var sTextBody = "Test send mail from Promotic application.";
var sBody = "To: " + sTo + "\n" + "From: " + sFrom + "\n" + "Subject: " + sSubject + "\n\n" + sTextBody;

var bDone = Pm.FileTextWrite(sPath + sFileName, sBody);
if (bDone)
{
var sSend = "--ssl-reqd " + sSmtp + " --mail-from " + sFrom + " --mail-rcpt " + sTo + " --upload-file " + sFileName + " --user " + sUser;
Pm.CreateProcess("curl " + sSend, sPath);
}


Script to send an email using PowerShell technology:
JavaScriptVBScriptSelect and copy to clipboard

var sEmail = "";
sEmail += "$emailSmtpServer = 'smtp.aol.com'\n";   // SMTP server
sEmail += "$emailSmtpServerPort = '587'\n";   // Port 465, 587, ...
sEmail += "$emailFrom = 'name@aol.com'\n";   // Sender's email address
sEmail += "$emailSmtpUser = 'nameid'\n";   // Your UserID on the SMTP server
sEmail += "$emailSmtpPass = 'password'\n";   // Your password on the SMTP server
sEmail += "$emailTo = 'test@gmail.com'\n";

sEmail += "$emailMessage = New-Object System.Net.Mail.MailMessage($emailFrom, $emailTo)\n";
sEmail += "$emailMessage.Subject = 'Test send mail'\n";   // Subject message
sEmail += "$emailMessage.Body = 'Test send mail from Promotic application.'\n";   // Text body message
sEmail += "$SMTPClient = New-Object System.Net.Mail.SmtpClient($emailSmtpServer, $emailSmtpServerPort)\n";
sEmail += "$SMTPClient.EnableSsl = $True\n";
sEmail += "$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($emailSmtpUser, $emailSmtpPass)\n";
sEmail += "$SMTPClient.Send($emailMessage)\n";

var sFilePath = Pm.DiscGetPath("#data:Email.ps1");
var bDone = Pm.FileTextWrite(sFilePath, sEmail);
if (bDone)
{
var oShell = Pm.AxGetObject("new", "WScript.Shell");
oShell.Run("Powershell -executionpolicy remotesigned -File " + sFilePath, 0, true);
}
Pm.FileDelete(sFilePath);


Script to send email from Thunderbird:
JavaScriptVBScriptSelect and copy to clipboard

var sTo = "test@gmail.com";
var sSubject = "Test send mail";
var sBody = "Test send mail from Promotic application.";
var sPath = "c:/Program Files (x86)/Mozilla Thunderbird/";
var sParams = "-compose subject=" + sSubject + ",to=" + sTo + ",body=" + sBody;
Pm.ShellExecute("open", sPath + "thunderbird.exe", sParams, 3);

History:
Pm8.00.01: Created
PROMOTIC 9.0.31 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.